/*
 This file is part of the OdinMS Maple Story Server
 Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc> 
 Matthias Butz <matze@odinms.de>
 Jan Christian Meyer <vimes@odinms.de>

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License version 3
 as published by the Free Software Foundation. You may not use, modify
 or distribute this program under any other version of the
 GNU Affero General Public License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package scripting;

import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;

import client.inventory.Equip;
import client.ISkill;
import client.inventory.IItem;
import client.MapleCharacter;
import constants.GameConstants;
import client.inventory.ItemFlag;
import client.MapleClient;
import client.MapleJob;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import client.SkillFactory;
import client.SkillEntry;
import client.MapleStat;
import client.inventory.Item;
import client.inventory.ItemLoader;
import constants.ServerConfig;
import database.DBConPool;
import database.DatabaseConnection;
import server.MapleCarnivalParty;
import server.Randomizer;
import server.MapleInventoryManipulator;
import server.MapleShopFactory;
import server.MapleSquad;
import server.maps.MapleMap;
import server.maps.Event_DojoAgent;
import server.maps.AramiaFireWorks;
import server.quest.MapleQuest;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.packet.PlayerShopPacket;
import server.MapleItemInformationProvider;
import handling.channel.ChannelServer;
import handling.channel.MapleGuildRanking;
import handling.channel.handler.InterServerHandler;
import handling.channel.handler.InventoryHandler;
import handling.world.MapleParty;
import handling.world.MaplePartyCharacter;
import handling.world.World;
import handling.world.guild.MapleGuild;
import server.MapleCarnivalChallenge;
import java.util.HashMap;
import handling.world.guild.MapleGuildAlliance;
import java.util.Arrays;
import java.util.Calendar;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Invocable;
import static server.MapleCarnivalChallenge.getJobNameById;
import server.MaplePortal;
import server.MapleStatEffect;
import server.MerchItemPackage;
import server.SpeedRunner;
import server.maps.SpeedRunType;
import server.StructPotentialItem;
import server.Timer;
import server.Timer.CloneTimer;
import server.gashapon.Gashapon;
import server.gashapon.GashaponFactory;
import server.life.MapleMonster;
import server.life.MapleMonsterInformationProvider;
import server.life.MonsterDropEntry;
import server.maps.Event_PyramidSubway;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.shops.HiredMerchant;
import tools.FilePrinter;
import tools.FileoutputUtil;
import tools.SearchGenerator;
import tools.StringUtil;

public class NPCConversationManager extends AbstractPlayerInteraction {

    private final MapleClient c;
    private final int npc, questid, mode;
    protected String script;
    private String getText;
    private final byte type; // -1 = NPC, 0 = start quest, 1 = end quest
    private byte lastMsg = -1;
    public boolean pendingDisposal = false;
    private final Invocable iv;
    public int p = 0;

    public NPCConversationManager(MapleClient c, int npc, int questid, int mode, String npcscript, byte type, Invocable iv) {
        super(c);
        this.c = c;
        this.npc = npc;
        this.questid = questid;
        this.mode = mode;
        this.type = type;
        this.iv = iv;
        this.script = npcscript;
    }

    public Invocable getIv() {
        return iv;
    }

    public int getMode() {
        return mode;
    }

    public int getNpc() {
        return npc;
    }

    public int getQuest() {
        return questid;
    }

    public String getScript() {
        return script;
    }

    public byte getType() {
        return type;
    }

    public void safeDispose() {
        pendingDisposal = true;
    }

    public void dispose() {
        NPCScriptManager.getInstance().dispose(c);
    }

    public void askMapSelection(final String sel) {
        if (lastMsg > -1) {
            return;
        }
        c.sendPacket(MaplePacketCreator.getMapSelection(npc, sel));
        lastMsg = 0xD;
    }

    public void sendNext(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { //sendNext will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 01", (byte) 0));
        lastMsg = 0;
    }

    public void sendNextS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimpleS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 01", type));
        lastMsg = 0;
    }

    public void sendPrev(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 00", (byte) 0));
        lastMsg = 0;
    }

    public void sendPrevS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimpleS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 00", type));
        lastMsg = 0;
    }

    public void sendNextPrev(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 01", (byte) 0));
        lastMsg = 0;
    }

    public void PlayerToNpc(String text) {
        sendNextPrevS(text, (byte) 3);
    }

    public void sendNextPrevS(String text) {
        sendNextPrevS(text, (byte) 3);
    }

    public void sendNextPrevS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimpleS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 01", type));
        lastMsg = 0;

    }

    public void sendOk(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 00", (byte) 0));
        lastMsg = 0;
    }

    public void sendOkS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimpleS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 00", type));
        lastMsg = 0;
    }

    public void sendYesNo(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 1, text, "", (byte) 0));
        lastMsg = 1;
    }

    public void sendYesNoS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimpleS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 1, text, "", type));
        lastMsg = 1;
    }

    public void sendAcceptDecline(String text) {
        askAcceptDecline(text);
    }

    public void sendAcceptDeclineNoESC(String text) {
        askAcceptDeclineNoESC(text);
    }

    public void askAcceptDecline(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0x0B, text, "", (byte) 0));
        lastMsg = 0xB;
    }

    public void askAcceptDeclineNoESC(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0x0C, text, "", (byte) 0));
        lastMsg = 0xC;
    }

    public void askAvatar(String text, int... args) {
        if (lastMsg > -1) {
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalkStyle(npc, text, args));
        lastMsg = 7;
    }

    public void sendSimple(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (!text.contains("#L")) { //sendSimple will dc otherwise!
            sendNext(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 4, text, "", (byte) 0));
        lastMsg = 4;
    }

    public void sendSimpleS(String text, byte type) {
        if (lastMsg > -1) {
            return;
        }
        if (!text.contains("#L")) { //sendSimple will dc otherwise!
            sendNextS(text, type);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 4, text, "", (byte) type));
        lastMsg = 4;
    }

    public void sendStyle(String text, int styles[]) {
        if (lastMsg > -1) {
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalkStyle(npc, text, styles));
        lastMsg = 7;
    }

    public void sendGetNumber(String text, int def, int min, int max) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalkNum(npc, text, def, min, max));
        lastMsg = 3;
    }

    public void sendGetText(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalkText(npc, text));
        lastMsg = 2;
    }

    public void setGetText(String text) {
        this.getText = text;
    }

    public String getText() {
        return getText;
    }

    public void setHair(int hair) {
        getPlayer().setHair(hair);
        getPlayer().updateSingleStat(MapleStat.HAIR, hair);
        getPlayer().equipChanged();
    }

    public void setFace(int face) {
        getPlayer().setFace(face);
        getPlayer().updateSingleStat(MapleStat.FACE, face);
        getPlayer().equipChanged();
    }

    public void setSkin(int color) {
        getPlayer().setSkinColor((byte) color);
        getPlayer().updateSingleStat(MapleStat.SKIN, color);
        getPlayer().equipChanged();
    }

    public int setRandomAvatar(int ticket, int... args_all) {
        if (!haveItem(ticket)) {
            return -1;
        }
        gainItem(ticket, (short) -1);

        int args = args_all[Randomizer.nextInt(args_all.length)];
        if (args < 100) {
            c.getPlayer().setSkinColor((byte) args);
            c.getPlayer().updateSingleStat(MapleStat.SKIN, args);
        } else if (args < 30000) {
            c.getPlayer().setFace(args);
            c.getPlayer().updateSingleStat(MapleStat.FACE, args);
        } else {
            c.getPlayer().setHair(args);
            c.getPlayer().updateSingleStat(MapleStat.HAIR, args);
        }
        c.getPlayer().equipChanged();

        return 1;
    }

    public int setAvatar(int ticket, int args) {
        if (!haveItem(ticket)) {
            return -1;
        }
        gainItem(ticket, (short) -1);

        if (args < 100) {
            c.getPlayer().setSkinColor((byte) args);
            c.getPlayer().updateSingleStat(MapleStat.SKIN, args);
        } else if (args < 30000) {
            c.getPlayer().setFace(args);
            c.getPlayer().updateSingleStat(MapleStat.FACE, args);
        } else {
            c.getPlayer().setHair(args);
            c.getPlayer().updateSingleStat(MapleStat.HAIR, args);
        }
        c.getPlayer().equipChanged();

        return 1;
    }

    public void sendStorage() {
        if (getPlayer().hasBlockedInventory2(true)) { //hack
            c.getPlayer().dropMessage(1, "系統錯誤，請联繫管理員。");
            c.sendPacket(MaplePacketCreator.enableActions());
            return;
        }

        if (!World.isShutDown) {
            if (!World.isShopShutDown) {
                c.getPlayer().setConversation(4);
                c.getPlayer().getStorage().sendStorage(c, npc);
            } else {
                c.getPlayer().dropMessage(1, "目前不能使用仓库。");
                c.sendPacket(MaplePacketCreator.enableActions());
            }
        } else {
            c.getPlayer().dropMessage(1, "目前不能使用仓库。");
            c.sendPacket(MaplePacketCreator.enableActions());
        }
    }

    public void openShop(int id) {
        MapleShopFactory.getInstance().getShop(id).sendShop(c);
    }

    public int gainGachaponItem(int id, int quantity) {
        return gainGachaponItem(id, quantity, c.getPlayer().getMap().getStreetName() + " - " + c.getPlayer().getMap().getMapName());
    }

    public int gainGachaponItem(int id, int quantity, final String msg) {
        try {
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                return -1;
            }
            final IItem item = MapleInventoryManipulator.addbyId_Gachapon(c, id, (short) quantity);

            if (item == null) {
                return -1;
            }
            final byte rareness = GameConstants.gachaponRareItem(item.getItemId());
            if (rareness == 1) {
                if (c.getPlayer().getMapId() == 910000000) {
                    World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[自由市場]", " : 恭喜玩家 " + c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                } else {
                    World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[隱藏地图-轉蛋屋]", " : 恭喜玩家 " + c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                }
                //World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他抽到了，大家恭喜他吧！", item, rareness));
            } else if (rareness == 2) {
                World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他成功轉到了，大家恭喜他吧！", item, rareness));
            } else if (rareness > 2) {
                World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他從楓葉转蛋机轉到了，大家恭喜他吧！", item, rareness));
            }
            return item.getItemId();
        } catch (Exception e) {
        }
        return -1;
    }

    public int gainGachaponItemTime(int id, int quantity, long period) {
        return gainGachaponItemTime(id, quantity, c.getPlayer().getMap().getStreetName() + " - " + c.getPlayer().getMap().getMapName(), period);
    }

    public int gainGachaponItemTime(int id, int quantity, final String msg, long period) {
        try {
            final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            if (!ii.itemExists(id)) {
                return -1;
            }
            final IItem item = ii.isCash(id) ? MapleInventoryManipulator.addbyId_GachaponTime(c, id, (short) quantity, period) : MapleInventoryManipulator.addbyId_Gachapon(c, id, (short) quantity);

            if (item == null) {
                return -1;
            }
            final byte rareness = GameConstants.gachaponRareItem(item.getItemId());
            if (rareness == 1) {
                if (c.getPlayer().getMapId() == 910000000) {
                    World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[自由市場]", " : 恭喜玩家 " + c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                } else {
                    World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[隱藏地图-轉蛋屋]", " : 恭喜玩家 " + c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                }
                //World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他抽到了，大家恭喜他吧！", item, rareness));
            } else if (rareness == 2) {
                World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他成功轉到了，大家恭喜他吧！", item, rareness));
            } else if (rareness > 2) {
                World.Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + c.getPlayer().getName(), " : 被他從楓葉转蛋机轉到了，大家恭喜他吧！", item, rareness));
            }
            return item.getItemId();
        } catch (Exception e) {
        }
        return -1;
    }

    public void changeJob(int job) {
        c.getPlayer().changeJob(job);
    }

    public void startQuest(int id) {
        MapleQuest.getInstance(id).start(getPlayer(), npc);
    }

    public void completeQuest(int id) {
        MapleQuest.getInstance(id).complete(getPlayer(), npc);
    }

    public void forfeitQuest(int id) {
        MapleQuest.getInstance(id).forfeit(getPlayer());
    }

    public void forceStartQuest() {
        MapleQuest.getInstance(questid).forceStart(getPlayer(), getNpc(), null);
    }

    @Override
    public void forceStartQuest(int id) {
        MapleQuest.getInstance(id).forceStart(getPlayer(), getNpc(), null);
    }

    public void forceStartQuest(String customData) {
        MapleQuest.getInstance(questid).forceStart(getPlayer(), getNpc(), customData);
    }

    public void forceCompleteQuest() {
        MapleQuest.getInstance(questid).forceComplete(getPlayer(), getNpc());
    }

    @Override
    public void forceCompleteQuest(final int id) {
        MapleQuest.getInstance(id).forceComplete(getPlayer(), getNpc());
    }

    public String getQuestCustomData() {
        return c.getPlayer().getQuestNAdd(MapleQuest.getInstance(questid)).getCustomData();
    }

    public void setQuestCustomData(String customData) {
        getPlayer().getQuestNAdd(MapleQuest.getInstance(questid)).setCustomData(customData);
    }

    public int getMeso() {
        return getPlayer().getMeso();
    }

    public void gainAp(final int amount) {
        c.getPlayer().gainAp((short) amount);
    }

    public void expandInventory(byte type, int amt) {
        c.getPlayer().expandInventory(type, amt);
    }

    public void unequipEverything() {
        MapleInventory equipped = getPlayer().getInventory(MapleInventoryType.EQUIPPED);
        MapleInventory equip = getPlayer().getInventory(MapleInventoryType.EQUIP);
        List<Short> ids = new LinkedList<>();
        for (IItem item : equipped.list()) {
            ids.add(item.getPosition());
        }
        for (short id : ids) {
            MapleInventoryManipulator.unequip(getC(), id, equip.getNextFreeSlot());
        }
    }

    public final void clearSkills() {
        Map<ISkill, SkillEntry> skills = getPlayer().getSkills();
        for (Entry<ISkill, SkillEntry> skill : skills.entrySet()) {
            getPlayer().changeSkillLevel(skill.getKey(), (byte) 0, (byte) 0);
        }
    }

    public boolean hasSkill(int skillid) {
        ISkill theSkill = SkillFactory.getSkill(skillid);
        if (theSkill != null) {
            return c.getPlayer().getSkillLevel(theSkill) > 0;
        }
        return false;
    }

    public void showEffect(boolean broadcast, String effect) {
        if (broadcast) {
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.showEffect(effect));
        } else {
            c.sendPacket(MaplePacketCreator.showEffect(effect));
        }
    }

    public void playSound(boolean broadcast, String sound) {
        if (broadcast) {
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.playSound(sound));
        } else {
            c.sendPacket(MaplePacketCreator.playSound(sound));
        }
    }

    public void environmentChange(boolean broadcast, String env) {
        if (broadcast) {
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.environmentChange(env, 2));
        } else {
            c.sendPacket(MaplePacketCreator.environmentChange(env, 2));
        }
    }

    public void updateBuddyCapacity(int capacity) {
        c.getPlayer().setBuddyCapacity((byte) capacity);
    }

    public int getBuddyCapacity() {
        return c.getPlayer().getBuddyCapacity();
    }

    public int partyMembersInMap() {
        int inMap = 0;
        for (MapleCharacter char2 : getPlayer().getMap().getCharactersThreadsafe()) {
            if (char2.getParty() == getPlayer().getParty()) {
                inMap++;
            }
        }
        return inMap;
    }

    public List<MapleCharacter> getPartyMembers() {
        if (getPlayer().getParty() == null) {
            return null;
        }
        List<MapleCharacter> chars = new LinkedList<>(); // creates an empty array full of shit..
        for (MaplePartyCharacter chr : getPlayer().getParty().getMembers()) {
            for (ChannelServer channel : ChannelServer.getAllInstances()) {
                MapleCharacter ch = channel.getPlayerStorage().getCharacterById(chr.getId());
                if (ch != null) { // double check <3
                    chars.add(ch);
                }
            }
        }
        return chars;
    }

    public void warpPartyWithExp(int mapId, int exp) {
        MapleMap target = getMap(mapId);
        for (MaplePartyCharacter chr : getPlayer().getParty().getMembers()) {
            MapleCharacter curChar = c.getChannelServer().getPlayerStorage().getCharacterByName(chr.getName());
            if ((curChar.getEventInstance() == null && getPlayer().getEventInstance() == null) || curChar.getEventInstance() == getPlayer().getEventInstance()) {
                curChar.changeMap(target, target.getPortal(0));
                curChar.gainExp(exp, true, false, true);
            }
        }
    }

    public void warpPartyWithExpMeso(int mapId, int exp, int meso) {
        MapleMap target = getMap(mapId);
        for (MaplePartyCharacter chr : getPlayer().getParty().getMembers()) {
            MapleCharacter curChar = c.getChannelServer().getPlayerStorage().getCharacterByName(chr.getName());
            if ((curChar.getEventInstance() == null && getPlayer().getEventInstance() == null) || curChar.getEventInstance() == getPlayer().getEventInstance()) {
                curChar.changeMap(target, target.getPortal(0));
                curChar.gainExp(exp, true, false, true);
                curChar.gainMeso(meso, true);
            }
        }
    }

    public MapleSquad getSquad(String type) {
        return c.getChannelServer().getMapleSquad(type);
    }

    public int getSquadAvailability(String type) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        }
        return squad.getStatus();
    }

    public boolean registerSquad(String type, int minutes, String startText) {
        if (c.getChannelServer().getMapleSquad(type) == null) {
            final MapleSquad squad = new MapleSquad(c.getChannel(), type, c.getPlayer(), minutes * 60 * 1000, startText);
            final boolean ret = c.getChannelServer().addMapleSquad(squad, type);
            if (ret) {
                final MapleMap map = c.getPlayer().getMap();

                map.broadcastMessage(MaplePacketCreator.getClock(minutes * 60));
                map.broadcastMessage(MaplePacketCreator.serverNotice(6, c.getPlayer().getName() + startText));
            } else {
                squad.clear();
            }
            return ret;
        }
        return false;
    }

    public boolean getSquadList(String type, byte type_) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return false;
        }
        if (type_ == 0 || type_ == 3) { // Normal viewing
            sendNext(squad.getSquadMemberString(type_));
        } else if (type_ == 1) { // Squad Leader banning, Check out banned participant
            sendSimple(squad.getSquadMemberString(type_));
        } else if (type_ == 2) {
            if (squad.getBannedMemberSize() > 0) {
                sendSimple(squad.getSquadMemberString(type_));
            } else {
                sendNext(squad.getSquadMemberString(type_));
            }
        }
        return true;

    }

    public byte isSquadLeader(String type) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        } else if (squad.getLeader() != null && squad.getLeader().getId() == c.getPlayer().getId()) {
            return 1;
        } else {
            return 0;
        }
    }

    public boolean reAdd(String eim, String squad) {
        EventInstanceManager eimz = getDisconnected(eim);
        MapleSquad squadz = getSquad(squad);
        if (eimz != null && squadz != null) {
            squadz.reAddMember(getPlayer());
            eimz.registerPlayer(getPlayer());
            return true;
        }
        return false;
    }

    public void banMember(String type, int pos) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            squad.banMember(pos);
        }
    }

    public void acceptMember(String type, int pos) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            squad.acceptMember(pos);
        }
    }

    public String getReadableMillis(long startMillis, long endMillis) {
        return StringUtil.getReadableMillis(startMillis, endMillis);
    }

    public int addMember(String type, boolean join) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            return squad.addMember(c.getPlayer(), join);
        }
        return -1;
    }

    public byte isSquadMember(String type) {
        final MapleSquad squad = c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        } else if (squad.getMembers().contains(c.getPlayer().getName())) {
            return 1;
        } else if (squad.isBanned(c.getPlayer())) {
            return 2;
        } else {
            return 0;
        }
    }

    public void resetReactors() {
        getPlayer().getMap().resetReactors();
    }

    public void genericGuildMessage(int code) {
        c.sendPacket(MaplePacketCreator.genericGuildMessage((byte) code));
    }

    public void disbandGuild() {
        final int gid = c.getPlayer().getGuildId();
        if (gid <= 0 || c.getPlayer().getGuildRank() != 1) {
            return;
        }
        World.Guild.disbandGuild(gid);
    }

    public void increaseGuildCapacity() {
        if (c.getPlayer().getMeso() < 250000) {
            c.sendPacket(MaplePacketCreator.serverNotice(1, "You do not have enough mesos."));
            return;
        }
        final int gid = c.getPlayer().getGuildId();
        if (gid <= 0) {
            return;
        }
        World.Guild.increaseGuildCapacity(gid);
        c.getPlayer().gainMeso(-250000, true, false, true);
    }

    public void displayGuildRanks() {
        c.sendPacket(MaplePacketCreator.showGuildRanks(npc, MapleGuildRanking.getInstance().getGuildRank()));
    }

    public void showlvl() {
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().getLevelRank()));
    }

    public void showmeso() {
        c.sendPacket(MaplePacketCreator.showmesoRanks(npc, MapleGuildRanking.getInstance().getMesoRank()));
    }

    public boolean removePlayerFromInstance() {
        if (c.getPlayer().getEventInstance() != null) {
            c.getPlayer().getEventInstance().removePlayer(c.getPlayer());
            return true;
        }
        return false;
    }

    public boolean isPlayerInstance() {
        return c.getPlayer().getEventInstance() != null;
    }

    public void changeStat(byte slot, int type, short amount) {
        Equip sel = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(slot);
        switch (type) {
            case 0:
                sel.setStr(amount);
                break;
            case 1:
                sel.setDex(amount);
                break;
            case 2:
                sel.setInt(amount);
                break;
            case 3:
                sel.setLuk(amount);
                break;
            case 4:
                sel.setHp(amount);
                break;
            case 5:
                sel.setMp(amount);
                break;
            case 6:
                sel.setWatk(amount);
                break;
            case 7:
                sel.setMatk(amount);
                break;
            case 8:
                sel.setWdef(amount);
                break;
            case 9:
                sel.setMdef(amount);
                break;
            case 10:
                sel.setAcc(amount);
                break;
            case 11:
                sel.setAvoid(amount);
                break;
            case 12:
                sel.setHands(amount);
                break;
            case 13:
                sel.setSpeed(amount);
                break;
            case 14:
                sel.setJump(amount);
                break;
            case 15:
                sel.setUpgradeSlots((byte) amount);
                break;
            case 16:
                sel.setViciousHammer((byte) amount);
                break;
            case 17:
                sel.setLevel((byte) amount);
                break;
            case 18:
                sel.setEnhance((byte) amount);
                break;
            case 19:
                sel.setPotential1(amount);
                break;
            case 20:
                sel.setPotential2(amount);
                break;
            case 21:
                sel.setPotential3(amount);
                break;
            case 22:
                sel.setOwner(getText());
                break;
            default:
                break;
        }
        c.getPlayer().equipChanged();
    }

    public void cleardrops() {
        MapleMonsterInformationProvider.getInstance().clearDrops();
    }

    public void killAllMonsters() {
        MapleMap map = c.getPlayer().getMap();
        double range = Double.POSITIVE_INFINITY;
        MapleMonster mob;
        for (MapleMapObject monstermo : map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.MONSTER))) {
            mob = (MapleMonster) monstermo;
            if (mob.getStats().isBoss()) {
                map.killMonster(mob, c.getPlayer(), false, false, (byte) 1);
            }
        }
        /*int mapid = c.getPlayer().getMapId();
         MapleMap map = c.getChannelServer().getMapFactory().getMap(mapid);
         map.killAllMonsters(true); // No drop. */
    }

    public void giveMerchantMesos() {
        long mesos = 0;
        try (Connection con = DBConPool.getInstance().getDataSource().getConnection()) {
            PreparedStatement ps = (PreparedStatement) con.prepareStatement("SELECT mesos FROM hiredmerchants WHERE merchantid = ?");
            ps.setInt(1, getPlayer().getId());
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
            } else {
                mesos = rs.getLong("mesos");
            }
            rs.close();
            ps.close();

            ps = (PreparedStatement) con.prepareStatement("UPDATE hiredmerchants SET mesos = 0 WHERE merchantid = ?");
            ps.setInt(1, getPlayer().getId());
            ps.executeUpdate();
            ps.close();

        } catch (SQLException ex) {
            System.err.println("Error gaining mesos in hired merchant" + ex);
            FileoutputUtil.outError("logs/資料庫異常.txt", ex);
        }
        c.getPlayer().gainMeso((int) mesos, true);
    }

    public void dc() {
        MapleCharacter victim = getChannelServer().getPlayerStorage().getCharacterByName(getPlayer().getName());
        victim.getClient().getSession().close();
        victim.getClient().disconnect(true, false);
    }

    public long getMerchantMesos() {
        long mesos = 0;
        try (Connection con = DBConPool.getInstance().getDataSource().getConnection(); PreparedStatement ps = (PreparedStatement) con.prepareStatement("SELECT mesos FROM hiredmerchants WHERE merchantid = ?")) {
            ps.setInt(1, getPlayer().getId());
            try (ResultSet rs = ps.executeQuery()) {
                if (!rs.next()) {
                    rs.close();
                    ps.close();
                } else {
                    mesos = rs.getLong("mesos");
                }
            }
        } catch (SQLException ex) {
            System.err.println("Error gaining mesos in hired merchant" + ex);
            FileoutputUtil.outError("logs/資料庫異常.txt", ex);
        }
        return mesos;
    }

    public void openDuey() {
        c.getPlayer().setConversation(2);
        c.sendPacket(MaplePacketCreator.sendDuey((byte) 9, null));
    }

    public void openMerchantItemStore() {
        if (!World.isShutDown) {
            c.getPlayer().setConversation(3);
            c.sendPacket(PlayerShopPacket.merchItemStore((byte) 0x22));
        } else {
            c.getPlayer().dropMessage(1, "目前不能使用精灵商人領取。");
            c.sendPacket(MaplePacketCreator.enableActions());
        }
    }

    public void sendRepairWindow() {
        c.sendPacket(MaplePacketCreator.sendRepairWindow(npc));
    }

    public final int getDojoPoints() {
        return c.getPlayer().getDojo();
    }

    public void setDojoPoints(int point) {
        c.getPlayer().setDojo(c.getPlayer().getDojo() + point);
    }

    public final int getDojoRecord() {
        return c.getPlayer().getDojoRecord();
    }

    public void setDojoRecord(final boolean reset) {
        c.getPlayer().setDojoRecord(reset);
    }

    public boolean start_DojoAgent(final boolean dojo, final boolean party) {
        if (dojo) {
            return Event_DojoAgent.warpStartDojo(c.getPlayer(), party);
        }
        return Event_DojoAgent.warpStartAgent(c.getPlayer(), party);
    }

    public boolean start_PyramidSubway(final int pyramid) {
        if (pyramid >= 0) {
            return Event_PyramidSubway.warpStartPyramid(c.getPlayer(), pyramid);
        }
        return Event_PyramidSubway.warpStartSubway(c.getPlayer());
    }

    public boolean bonus_PyramidSubway(final int pyramid) {
        if (pyramid >= 0) {
            return Event_PyramidSubway.warpBonusPyramid(c.getPlayer(), pyramid);
        }
        return Event_PyramidSubway.warpBonusSubway(c.getPlayer());
    }

    public final short getKegs() {
        return AramiaFireWorks.getInstance().getKegsPercentage();
    }

    public void giveKegs(final int kegs) {
        AramiaFireWorks.getInstance().giveKegs(c.getPlayer(), kegs);
    }

    public final short getSunshines() {
        return AramiaFireWorks.getInstance().getSunsPercentage();
    }

    public void addSunshines(final int kegs) {
        AramiaFireWorks.getInstance().giveSuns(c.getPlayer(), kegs);
    }

    public final short getDecorations() {
        return AramiaFireWorks.getInstance().getDecsPercentage();
    }

    public void addDecorations(final int kegs) {
        try {
            AramiaFireWorks.getInstance().giveDecs(c.getPlayer(), kegs);
        } catch (Exception e) {
        }
    }

    public final MapleInventory getInventory(int type) {
        return c.getPlayer().getInventory(MapleInventoryType.getByType((byte) type));
    }

    public final MapleCarnivalParty getCarnivalParty() {
        return c.getPlayer().getCarnivalParty();
    }

    public final MapleCarnivalChallenge getNextCarnivalRequest() {
        return c.getPlayer().getNextCarnivalRequest();
    }

    public final MapleCarnivalChallenge getCarnivalChallenge(MapleCharacter chr) {
        return new MapleCarnivalChallenge(chr);
    }

    public void maxStats() {
        Map<MapleStat, Integer> statup = new EnumMap<>(MapleStat.class);
        c.getPlayer().getStat().setStr((short) 32767);
        c.getPlayer().getStat().setDex((short) 32767);
        c.getPlayer().getStat().setInt((short) 32767);
        c.getPlayer().getStat().setLuk((short) 32767);

        c.getPlayer().getStat().setMaxHp((short) 30000);
        c.getPlayer().getStat().setMaxMp((short) 30000);
        c.getPlayer().getStat().setHp((short) 30000);
        c.getPlayer().getStat().setMp((short) 30000);

        statup.put(MapleStat.STR, 32767);
        statup.put(MapleStat.DEX, 32767);
        statup.put(MapleStat.LUK, 32767);
        statup.put(MapleStat.INT, 32767);
        statup.put(MapleStat.HP, 30000);
        statup.put(MapleStat.MAXHP, 30000);
        statup.put(MapleStat.MP, 30000);
        statup.put(MapleStat.MAXMP, 30000);

        c.sendPacket(MaplePacketCreator.updatePlayerStats(statup, c.getPlayer()));
    }

    public Pair<String, Map<Integer, String>> getSpeedRun(String typ) {
        final SpeedRunType stype = SpeedRunType.valueOf(typ);
        if (SpeedRunner.getInstance().getSpeedRunData(stype) != null) {
            return SpeedRunner.getInstance().getSpeedRunData(stype);
        }
        return new Pair<>("", new HashMap<>());
    }

    public boolean getSR(Pair<String, Map<Integer, String>> ma, int sel) {
        if (ma.getRight().get(sel) == null || ma.getRight().get(sel).length() <= 0) {
            dispose();
            return false;
        }
        sendOk(ma.getRight().get(sel));
        return true;
    }

    public Equip getEquip(int itemid) {
        return (Equip) MapleItemInformationProvider.getInstance().getEquipById(itemid);
    }

    public void setExpiration(Object statsSel, long expire) {
        if (statsSel instanceof Equip) {
            ((Equip) statsSel).setExpiration(System.currentTimeMillis() + (expire * 24 * 60 * 60 * 1000));
        }
    }

    public void setLock(Object statsSel) {
        if (statsSel instanceof Equip) {
            Equip eq = (Equip) statsSel;
            if (eq.getExpiration() == -1) {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.LOCK.getValue()));
            } else {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.UNTRADEABLE.getValue()));
            }
        }
    }

    public boolean addFromDrop(Object statsSel) {
        if (statsSel instanceof IItem) {
            final IItem it = (IItem) statsSel;
            return MapleInventoryManipulator.checkSpace(getClient(), it.getItemId(), it.getQuantity(), it.getOwner()) && MapleInventoryManipulator.addFromDrop(getClient(), it, false);
        }
        return false;
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int offset, String type) {
        return replaceItem(slot, invType, statsSel, offset, type, false);
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int offset, String type, boolean takeSlot) {
        MapleInventoryType inv = MapleInventoryType.getByType((byte) invType);
        if (inv == null) {
            return false;
        }
        IItem item = getPlayer().getInventory(inv).getItem((byte) slot);
        if (item == null || statsSel instanceof IItem) {
            item = (IItem) statsSel;
        }
        if (offset > 0) {
            if (inv != MapleInventoryType.EQUIP) {
                return false;
            }
            Equip eq = (Equip) item;
            if (takeSlot) {
                if (eq.getUpgradeSlots() < 1) {
                    return false;
                } else {
                    eq.setUpgradeSlots((byte) (eq.getUpgradeSlots() - 1));
                }
            }
            if (type.equalsIgnoreCase("Slots")) {
                eq.setUpgradeSlots((byte) (eq.getUpgradeSlots() + offset));
            } else if (type.equalsIgnoreCase("Level")) {
                eq.setLevel((byte) (eq.getLevel() + offset));
            } else if (type.equalsIgnoreCase("Hammer")) {
                eq.setViciousHammer((byte) (eq.getViciousHammer() + offset));
            } else if (type.equalsIgnoreCase("STR")) {
                eq.setStr((short) (eq.getStr() + offset));
            } else if (type.equalsIgnoreCase("DEX")) {
                eq.setDex((short) (eq.getDex() + offset));
            } else if (type.equalsIgnoreCase("INT")) {
                eq.setInt((short) (eq.getInt() + offset));
            } else if (type.equalsIgnoreCase("LUK")) {
                eq.setLuk((short) (eq.getLuk() + offset));
            } else if (type.equalsIgnoreCase("HP")) {
                eq.setHp((short) (eq.getHp() + offset));
            } else if (type.equalsIgnoreCase("MP")) {
                eq.setMp((short) (eq.getMp() + offset));
            } else if (type.equalsIgnoreCase("WATK")) {
                eq.setWatk((short) (eq.getWatk() + offset));
            } else if (type.equalsIgnoreCase("MATK")) {
                eq.setMatk((short) (eq.getMatk() + offset));
            } else if (type.equalsIgnoreCase("WDEF")) {
                eq.setWdef((short) (eq.getWdef() + offset));
            } else if (type.equalsIgnoreCase("MDEF")) {
                eq.setMdef((short) (eq.getMdef() + offset));
            } else if (type.equalsIgnoreCase("ACC")) {
                eq.setAcc((short) (eq.getAcc() + offset));
            } else if (type.equalsIgnoreCase("Avoid")) {
                eq.setAvoid((short) (eq.getAvoid() + offset));
            } else if (type.equalsIgnoreCase("Hands")) {
                eq.setHands((short) (eq.getHands() + offset));
            } else if (type.equalsIgnoreCase("Speed")) {
                eq.setSpeed((short) (eq.getSpeed() + offset));
            } else if (type.equalsIgnoreCase("Jump")) {
                eq.setJump((short) (eq.getJump() + offset));
            } else if (type.equalsIgnoreCase("ItemEXP")) {
                eq.setItemEXP(eq.getItemEXP() + offset);
            } else if (type.equalsIgnoreCase("Expiration")) {
                eq.setExpiration((long) (eq.getExpiration() + offset));
            } else if (type.equalsIgnoreCase("Flag")) {
                eq.setFlag((byte) (eq.getFlag() + offset));
            }
            if (eq.getExpiration() == -1) {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.LOCK.getValue()));
            } else {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.UNTRADEABLE.getValue()));
            }
            item = eq.copy();
        }
        MapleInventoryManipulator.removeFromSlot(getClient(), inv, (short) slot, item.getQuantity(), false);
        return MapleInventoryManipulator.addFromDrop(getClient(), item, false);
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int upgradeSlots) {
        return replaceItem(slot, invType, statsSel, upgradeSlots, "Slots");
    }

    public boolean isCash(final int itemId) {
        return MapleItemInformationProvider.getInstance().isCash(itemId);
    }

    public void buffGuild(final int buff, final int duration, final String msg) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        if (ii.getItemEffect(buff) != null && getPlayer().getGuildId() > 0) {
            final MapleStatEffect mse = ii.getItemEffect(buff);
            for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharactersThreadSafe()) {
                    if (chr.getGuildId() == getPlayer().getGuildId()) {
                        mse.applyTo(chr, chr, true, null, duration);
                        chr.dropMessage(5, "Your guild has gotten a " + msg + " buff.");
                    }
                }
            }
        }
    }

    public boolean createAlliance(String alliancename) {
        MapleParty pt = c.getPlayer().getParty();
        MapleCharacter otherChar = c.getChannelServer().getPlayerStorage().getCharacterById(pt.getMemberByIndex(1).getId());
        if (otherChar == null || otherChar.getId() == c.getPlayer().getId()) {
            return false;
        }
        try {
            return World.Alliance.createAlliance(alliancename, c.getPlayer().getId(), otherChar.getId(), c.getPlayer().getGuildId(), otherChar.getGuildId());
        } catch (Exception re) {
            return false;
        }
    }

    public boolean addCapacityToAlliance() {
        try {
            final MapleGuild gs = World.Guild.getGuild(c.getPlayer().getGuildId());
            if (gs != null && c.getPlayer().getGuildRank() == 1 && c.getPlayer().getAllianceRank() == 1) {
                if (World.Alliance.getAllianceLeader(gs.getAllianceId()) == c.getPlayer().getId() && World.Alliance.changeAllianceCapacity(gs.getAllianceId())) {
                    gainMeso(-MapleGuildAlliance.CHANGE_CAPACITY_COST);
                    return true;
                }
            }
        } catch (Exception re) {
        }
        return false;
    }

    public boolean disbandAlliance() {
        try {
            final MapleGuild gs = World.Guild.getGuild(c.getPlayer().getGuildId());
            if (gs != null && c.getPlayer().getGuildRank() == 1 && c.getPlayer().getAllianceRank() == 1) {
                if (World.Alliance.getAllianceLeader(gs.getAllianceId()) == c.getPlayer().getId() && World.Alliance.disbandAlliance(gs.getAllianceId())) {
                    return true;
                }
            }
        } catch (Exception re) {
        }
        return false;
    }

    public byte getLastMsg() {
        return lastMsg;
    }

    public final void setLastMsg(final byte last) {
        this.lastMsg = last;
    }

    public void setPartyBossLog(String bossid) {
        MapleParty party = getPlayer().getParty();
        for (MaplePartyCharacter pc : party.getMembers()) {
            MapleCharacter chr = World.getStorage(this.getChannelNumber()).getCharacterById(pc.getId());
            if (chr != null) {
                chr.setBossLog(bossid);
            }
        }
    }

    public final void maxAllSkills() {
        for (ISkill skil : SkillFactory.getAllSkills()) {
            if (GameConstants.isApplicableSkill(skil.getId())) { //no db/additionals/resistance skills
                teachSkill(skil.getId(), skil.getMaxLevel(), skil.getMaxLevel());
            }
        }
    }

    public final void resetStats(int str, int dex, int z, int luk) {
        c.getPlayer().resetStats(str, dex, z, luk);
    }

    public final boolean dropItem(int slot, int invType, int quantity) {
        MapleInventoryType inv = MapleInventoryType.getByType((byte) invType);
        if (inv == null) {
            return false;
        }
        return MapleInventoryManipulator.drop(c, inv, (short) slot, (short) quantity, true);
    }

    public final List<Integer> getAllPotentialInfo() {
        return new ArrayList<>(MapleItemInformationProvider.getInstance().getAllPotentialInfo().keySet());
    }

    public final String getPotentialInfo(final int id) {
        final List<StructPotentialItem> potInfo = MapleItemInformationProvider.getInstance().getPotentialInfo(id);
        final StringBuilder builder = new StringBuilder("#b#ePOTENTIAL INFO FOR ID: ");
        builder.append(id);
        builder.append("#n#k\r\n\r\n");
        int minLevel = 1, maxLevel = 10;
        for (StructPotentialItem item : potInfo) {
            builder.append("#eLevels ");
            builder.append(minLevel);
            builder.append("~");
            builder.append(maxLevel);
            builder.append(": #n");
            builder.append(item.toString());
            minLevel += 10;
            maxLevel += 10;
            builder.append("\r\n");
        }
        return builder.toString();
    }

    public final void sendRPS() {
        c.sendPacket(MaplePacketCreator.getRPSMode((byte) 8, -1, -1, -1));
    }

    public final void setQuestRecord(Object ch, final int questid, final String data) {
        ((MapleCharacter) ch).getQuestNAdd(MapleQuest.getInstance(questid)).setCustomData(data);
    }

    public final void doWeddingEffect(final Object ch) {
        final MapleCharacter chr = (MapleCharacter) ch;
        getMap().broadcastMessage(MaplePacketCreator.yellowChat(chr.getName() + ", 妳願意承認 " + getPlayer().getName() + " 做妳的丈夫，誠實遵照上帝的誡命，和他生活在一起，無論在什麼環境願順服他、愛惜他、安慰他、尊重他保護他，以致奉召歸主？？"));
        CloneTimer.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                if (chr == null || getPlayer() == null) {
                    warpMap(680000500, 0);
                } else {
                    getMap().broadcastMessage(MaplePacketCreator.yellowChat(getPlayer().getName() + ", 你願意承認接納 " + chr.getName() + " 做你的妻子，誠實遵照上帝的誡命，和她生活在一起，無論在什麼環境，願意終生養她、愛惜她、安慰她、尊重她、保護她，以至奉召歸主？？"));
                }
            }
        }, 10000);
        CloneTimer.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                if (chr == null || getPlayer() == null) {
                    if (getPlayer() != null) {
                        setQuestRecord(getPlayer(), 160001, "3");
                        setQuestRecord(getPlayer(), 160002, "0");
                    } else if (chr != null) {
                        setQuestRecord(chr, 160001, "3");
                        setQuestRecord(chr, 160002, "0");
                    }
                    warpMap(680000500, 0);
                } else {
                    setQuestRecord(getPlayer(), 160001, "2");
                    setQuestRecord(chr, 160001, "2");
                    sendNPCText(getPlayer().getName() + " 和 " + chr.getName() + "， 我希望你們兩個能在此時此刻永遠愛著對方！", 9201002);
                    getMap().startExtendedMapEffect("那麼現在請新娘親吻 " + getPlayer().getName() + "！", 5120006);
                    if (chr.getGuildId() > 0) {
                        World.Guild.guildPacket(chr.getGuildId(), MaplePacketCreator.sendMarriage(false, chr.getName()));
                    }
                    if (chr.getFamilyId() > 0) {
                        World.Family.familyPacket(chr.getFamilyId(), MaplePacketCreator.sendMarriage(true, chr.getName()), chr.getId());
                    }
                    if (getPlayer().getGuildId() > 0) {
                        World.Guild.guildPacket(getPlayer().getGuildId(), MaplePacketCreator.sendMarriage(false, getPlayer().getName()));
                    }
                    if (getPlayer().getFamilyId() > 0) {
                        World.Family.familyPacket(getPlayer().getFamilyId(), MaplePacketCreator.sendMarriage(true, chr.getName()), getPlayer().getId());
                    }
                }
            }
        }, 20000); //10 sec 10 sec
    }

    public void 开启小鋼珠(int type) {
        c.sendPacket(MaplePacketCreator.openBeans(getPlayer().getBeans(), type));
    }

    public void worldMessage(String text) {
        World.Broadcast.broadcastMessage(MaplePacketCreator.serverNotice(6, text));
    }

    public int getBeans() {
        return getClient().getPlayer().getBeans();
    }

    public void warpBack(int mid, final int retmap, final int time) { //时间秒數

        MapleMap warpMap = c.getChannelServer().getMapFactory().getMap(mid);
        c.getPlayer().changeMap(warpMap, warpMap.getPortal(0));
        c.sendPacket(MaplePacketCreator.getClock(time));
        Timer.EventTimer.getInstance().schedule(new Runnable() {
            @Override
            public void run() {
                MapleMap warpMap = c.getChannelServer().getMapFactory().getMap(retmap);
                if (c.getPlayer() != null) {
                    c.sendPacket(MaplePacketCreator.stopClock());
                    c.getPlayer().changeMap(warpMap, warpMap.getPortal(0));
                    c.getPlayer().dropMessage(6, "已經到達目的地了!");
                }
            }
        }, 1000 * time); //設定时间, (1 秒 = 1000)
    }

    public void ChangeName(String name) {
        getPlayer().setName(name);
        save();
        getPlayer().fakeRelog();
    }

    public String searchData(int type, String search) {
        return SearchGenerator.searchData(type, search);
    }

    public int[] getSearchData(int type, String search) {
        Map<Integer, String> data = SearchGenerator.getSearchData(type, search);
        if (data.isEmpty()) {
            return null;
        }
        int[] searches = new int[data.size()];
        int i = 0;
        for (int key : data.keySet()) {
            searches[i] = key;
            i++;
        }
        return searches;
    }

    public boolean foundData(int type, String search) {
        return SearchGenerator.foundData(type, search);
    }

    public boolean ReceiveMedal() {
        int acid = getPlayer().getAccountID();
        int id = getPlayer().getId();
        String name = getPlayer().getName();
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        int item = 1142475;
        if (!getPlayer().canHold(item)) {
            return false;
        } else if (getPlayer().haveItem(item)) {
            return false;
        }

        try (Connection con = DBConPool.getInstance().getDataSource().getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT id FROM RCmedals WHERE name = ?");
            ps.setString(1, name);
            ResultSet rs = ps.executeQuery();
            if (!rs.first()) {// 角色不存在於勳章表單
                return false;
            }
            ps.close();
            rs.close();
            ps = con.prepareStatement("Update RCmedals set amount = ? Where id = ?");
            ps.setInt(1, 0);
            ps.setInt(2, id);
            ps.execute();
            ps.close();
        } catch (Exception ex) {
            FilePrinter.printError("NPCConversationManager.txt", ex, "ReceiveMedal(" + name + ")");
            FileoutputUtil.outError("logs/資料庫異常.txt", ex);
        }
        IItem toDrop = ii.randomizeStats((Equip) ii.getEquipById(item));
        toDrop.setGMLog(getPlayer().getName() + " 領取勳章");
        MapleInventoryManipulator.addbyItem(c, toDrop);
        FileoutputUtil.logToFile("logs/Data/NPC領取勳章.txt", "\r\n " + FileoutputUtil.NowTime() + " IP: " + c.getSession().remoteAddress().toString().split(":")[0] + " 账号: " + c.getAccountName() + " 玩家: " + c.getPlayer().getName() + " 領取了RC勳章");
        return true;
    }

    public String ShowJobRank(int type) {
        StringBuilder sb = new StringBuilder();
        List<MapleGuildRanking.JobRankingInfo> Ranking = MapleGuildRanking.getInstance().getJobRank(type);
        if (Ranking != null) {
            int num = 0;
            for (MapleGuildRanking.JobRankingInfo info : Ranking) {
                num++;
                sb.append("#n#e#k排名:#r ");
                sb.append(num);
                sb.append("\r\n#n#e#k玩家名稱:#d ");
                sb.append(StringUtil.getRightPaddedStr(info.getName(), ' ', 13));
                sb.append("\r\n#n#e#k等級:#e#r ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getLevel()), ' ', 3));
                sb.append("\r\n#n#e#k职业:#e#b ");
                sb.append(MapleJob.getName(MapleJob.getById(info.getJob())));
                sb.append("\r\n#n#e#k力量:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getStr()), ' ', 4));
                sb.append("\r\n#n#e#k敏捷:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getDex()), ' ', 4));
                sb.append("\r\n#n#e#k智力:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getInt()), ' ', 4));
                sb.append("\r\n#n#e#k幸運:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getLuk()), ' ', 4));
                sb.append("\r\n");
                sb.append("#n#k======================================================\r\n");
            }
        } else {
            sb.append("#r查詢無任何結果唷");
        }
        return sb.toString();
    }

    public static boolean hairExists(int hair) {
        return MapleItemInformationProvider.hairList.containsKey(hair);
    }

    public int[] getCanHair(int[] hairs) {
        List<Integer> canHair = new ArrayList();
        List<Integer> cantHair = new ArrayList();
        for (int hair : hairs) {
            if (hairExists(hair)) {
                canHair.add(hair);
            } else {
                cantHair.add(hair);
            }
        }
        if (cantHair.size() > 0 && c.getPlayer().isAdmin()) {
            StringBuilder sb = new StringBuilder("正在讀取的发型裏有");
            sb.append(cantHair.size()).append("個发型客戶端不支持顯示，已經被清除：");
            for (int i = 0; i < cantHair.size(); i++) {
                sb.append(cantHair.get(i));
                if (i < cantHair.size() - 1) {
                    sb.append(",");
                }
            }
            playerMessage(sb.toString());
        }
        int[] getHair = new int[canHair.size()];
        for (int i = 0; i < canHair.size(); i++) {
            getHair[i] = canHair.get(i);
        }
        return getHair;
    }

    public static boolean faceExists(int face) {
        return MapleItemInformationProvider.faceLists.containsKey(face);
    }

    public int[] getCanFace(int[] faces) {
        List<Integer> canFace = new ArrayList();
        List<Integer> cantFace = new ArrayList();
        for (int face : faces) {
            if (faceExists(face)) {
                canFace.add(face);
            } else {
                cantFace.add(face);
            }
        }
        if (cantFace.size() > 0 && c.getPlayer().isAdmin()) {
            StringBuilder sb = new StringBuilder("正在讀取的脸型裏有");
            sb.append(cantFace.size()).append("個脸型客戶端不支持顯示，已經被清除：");
            for (int i = 0; i < cantFace.size(); i++) {
                sb.append(cantFace.get(i));
                if (i < cantFace.size() - 1) {
                    sb.append(",");
                }
            }
            playerMessage(sb.toString());
        }
        int[] getFace = new int[canFace.size()];
        for (int i = 0; i < canFace.size(); i++) {
            getFace[i] = canFace.get(i);
        }
        return getFace;
    }

    public String checkDrop(int mobId) {
        final List<MonsterDropEntry> ranks = MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId);
        if (ranks != null && ranks.size() > 0) {
            int num = 0, itemId = 0, ch = 0;
            MonsterDropEntry de;
            StringBuilder name = new StringBuilder();
            for (int i = 0; i < ranks.size(); i++) {
                de = ranks.get(i);
                if (de.chance > 0 && (de.questid <= 0 || (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0))) {
                    itemId = de.itemId;
                    if (num == 0) {
                        name.append("當前怪物 #o" + mobId + "# 的爆率為:\r\n");
                        name.append("--------------------------------------\r\n");
                    }
                    String namez = "#z" + itemId + "#";
                    if (itemId == 0) { //meso
                        itemId = 4031041; //display sack of cash
                        namez = (de.Minimum * getClient().getChannelServer().getMesoRate()) + " 到 " + (de.Maximum * getClient().getChannelServer().getMesoRate()) + " 金币";
                    }
                    ch = de.chance * getClient().getChannelServer().getDropRate();
                    name.append((num + 1) + ") #v" + itemId + "#" + namez /*+ " - " + (Integer.valueOf(ch >= 999999 ? 1000000 : ch).doubleValue() / 10000.0) + "% 爆率。 "*/ + (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0 ? ("需要接受任務 " + MapleQuest.getInstance(de.questid).getName() + "") : "") + "\r\n");
                    num++;
                }
            }
            if (name.length() > 0) {
                return name.toString();
            }

        }
        return "沒有當前怪物的爆率数据。";
    }

    public String checkDrop(MapleCharacter chr, int mobId, boolean GM) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        final List<MonsterDropEntry> ranks = MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId);
        if (ranks != null && ranks.size() > 0) {
            int num = 0, itemId = 0, ch = 0;
            MonsterDropEntry de;
            StringBuilder name = new StringBuilder();
            StringBuilder error = new StringBuilder();
            name.append("【#r#o" + mobId + "##k】掉寶物品查詢列表:#b" + "\r\n");
            for (int i = 0; i < ranks.size(); i++) {
                de = ranks.get(i);
                if (de.chance > 0 && (de.questid <= 0 || (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0))) {
                    itemId = de.itemId;
                    /*   if (num == 0) {
                        name.append("【#r#o"+ mobId + "##k】掉寶数据列表:#b" +"\r\n");
                    }*/
                    String namez = "#z" + itemId + "#";
                    if (itemId == 0) { //meso
                        itemId = 4031041; //display sack of cash
                        namez = (de.Minimum * getClient().getChannelServer().getMesoRate()) + " to " + (de.Maximum * getClient().getChannelServer().getMesoRate()) + " #b金币#l#k";
                    } else if (itemId != 0 && ii.itemExists(itemId)) {
                        ch = de.chance * getClient().getChannelServer().getDropRate();
                        if (GM == false) {
                            name.append("#k" + (num + 1) + ": #v" + itemId + "# " + namez + ((chr.isGM()) ? "#d  掉落機率：" + (Integer.valueOf(ch >= 999999 ? 1000000 : ch).doubleValue() / 10000.0) + "%\r\n" : "\r\n") + "#b(掉落條件:" + (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0 ? ("需要接取任務#r " + MapleQuest.getInstance(de.questid).getName() + " #b)\r\n") : "#r無#b)") + "\r\n");
                        } else {
                            name.append("#L" + itemId + "##k" + (num + 1) + ": #v" + itemId + "# " + namez + ((chr.isGM()) ? "#d  掉落機率：" + (Integer.valueOf(ch >= 999999 ? 1000000 : ch).doubleValue() / 10000.0) + "%(點選更改)\r\n" : "\r\n") + "#b(掉落條件:" + (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0 ? ("需要接取任務#r " + MapleQuest.getInstance(de.questid).getName() + " #b)\r\n") : "#r無#b)") + "\r\n");
                        }
                        //                       name.append("#k" + (num + 1) + ": #v" + itemId + "# " + namez + " #d" +"%\r\n#b(掉落條件:" + (de.questid > 0 && MapleQuest.getInstance(de.questid).getName().length() > 0 ? ("需要接取任務#r " + MapleQuest.getInstance(de.questid).getName() + " #b)\r\n") : "#r無#b)") + ((chr.isGM())?"掉落機率：" + (Integer.valueOf(ch >= 999999 ? 1000000 : ch).doubleValue() / 10000.0) +"\r\n":"\r\n"));

                        num++;
                    } else {
                        error.append(itemId + "\r\n");
                    }
                }
            }
            if (GM == true) {
                name.append("\r\n#L" + 10000 + "##k" + (num + 1) + ": #b我要額外新增掉落物品!");
            }
            if (error.length() > 0) {
                chr.dropMessage(1, "無效的物品ID:\r\n" + error.toString());
            }
            if (name.length() > 0) {
                return name.toString();
            }

        }
        return "該怪物查無任何掉寶数据。";
    }

    public void gainBeans(int s) {
        getPlayer().gainBeans(s);
        c.getSession().write(MaplePacketCreator.updateBeans(this.c.getPlayer()));
    }

    public void openBeans() {//打开豆豆机界面
        c.getSession().write(MaplePacketCreator.openBeans(getPlayer().getBeans(), 0));
        c.getPlayer().dropMessage(5, "按住左右鍵可以調整力道,建議調好角度一路給他打,不要按暫停若九宮格卡住沒反應請離開在近來");
    }

    public void setMonsterRiding(int itemid) {//装备不能正常装备的坐騎
        short src = getClient().getPlayer().haveItemPos(itemid);
        if (src == 100) {
            c.getPlayer().dropMessage(5, "你沒有當前坐騎。");
        } else {
            MapleInventoryManipulator.equip(c, src, (short) -18);
            c.getPlayer().dropMessage(5, "装备坐騎成功。");
        }
    }

    public int getRandom(int... args_all) {
        int args = args_all[Randomizer.nextInt(args_all.length)];
        return args;
    }

    public void OwlAdv(int point, int itemid) {
        owlse(this.c, point, itemid);
    }

    public static void owlse(MapleClient c, int point, int itemid) {
        int itemSearch = itemid;

        List<HiredMerchant> hms = new ArrayList<HiredMerchant>();
        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
            if (!cserv.searchMerchant(itemSearch).isEmpty()) {
                hms.addAll(cserv.searchMerchant(itemSearch));
            }
        }
        if (hms.size() > 0) {
            if (c.getPlayer().haveItem(5230000, 1)) {
                MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5230000, 1, true, false);
            } else if (c.getPlayer().getCSPoints(point) >= 5) {
                c.getPlayer().modifyCSPoints(point, -5, true);
            } else {
                c.getPlayer().dropMessage(1, "點數不足，無法查詢！");
                if (NPCScriptManager.getInstance().getCM(c) != null) {
                    NPCScriptManager.getInstance().dispose(c);
                    c.sendPacket(MaplePacketCreator.enableActions());
                }
            }

            if (NPCScriptManager.getInstance().getCM(c) != null) {
                NPCScriptManager.getInstance().dispose(c);
            }
            c.sendPacket(MaplePacketCreator.getOwlSearched(itemSearch, hms));
        } else {
            if (NPCScriptManager.getInstance().getCM(c) != null) {
                NPCScriptManager.getInstance().dispose(c);
                c.sendPacket(MaplePacketCreator.enableActions());
            }
            c.getPlayer().dropMessage(1, "找不到物品");
        }
    }

    public void checkMobs(MapleCharacter chr) {
        if (this.getMap().getAllMonstersThreadsafe().size() <= 0) {
            sendOk("#地图上沒有怪物哦!!。");
            dispose();
        }
        String msg = "玩家 #b" + chr.getName() + "#k 此地图怪物掉寶查詢:\r\n#r(若有任何掉寶問題,請至社團BUG區回報怪物名稱和代码)\r\n#d";
        Iterator monster = getMap().getAllUniqueMonsters().iterator();
        while (monster.hasNext()) {
            Object monsterid = monster.next();
//            msg += "#L" + monsterid + "##o" + monsterid + "#" + ((chr.isGM()) ? " 代码:" + monsterid + "#l\r\n" : "(查看)#l\r\n");
            msg += "#L" + monsterid + "##o" + monsterid + "#" + " 代码:" + monsterid + " (查看)#l\r\n";
        }
        sendOk(msg);
    }

    public void getMobs(int itemid) {
        MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
        final List<Integer> mobs = MapleMonsterInformationProvider.getInstance().getMobByItem(itemid);
        String text = "#d這些怪物会掉落您查詢的物品#k: \r\n\r\n";

        for (int i = 0; i < mobs.size(); i++) {
            int quest = 0;
            if (mi.getDropQuest(mobs.get(i)) > 0) {
                quest = mi.getDropQuest(mobs.get(i));
            }
            int chance = mi.getDropChance(mobs.get(i)) * getClient().getChannelServer().getDropRate();

            text += "#r#o" + mobs.get(i) + "##k " /*+ (Integer.valueOf(chance >= 999999 ? 1000000 : chance).doubleValue() / 10000.0) + "%" */ + (quest > 0 && MapleQuest.getInstance(quest).getName().length() > 0 ? ("#b需要進行 " + MapleQuest.getInstance(quest).getName() + " 任務來取得#k") : "") + "\r\n";

        }
        sendNext(text);
    }

    public Gashapon getGashapon() {
        return GashaponFactory.getInstance().getGashaponByNpcId(this.getNpc());
    }

    public void getGachaponMega(String msg, Item item, int quantity) {
        World.Broadcast.broadcastGashponmega(MaplePacketCreator.getGachaponMega(c.getPlayer().getName(), " : x" + quantity + "恭喜玩家 " + c.getPlayer().getName() + " 在" + msg + "获得！", item, (byte) 1, c.getPlayer().getClient().getChannel()));
    }

    public void EnterCS(int mod) {
        c.getPlayer().setCsMod(mod);
        InterServerHandler.EnterCashShop(c, c.getPlayer(), false);
    }

    public int[] getSavedFaces() {
        return getPlayer().getSavedFaces();
    }

    public int getSavedFace(int sel) {
        return getPlayer().getSavedFace(sel);
    }

    public void setSavedFace(int sel, int id) {
        getPlayer().setSavedFace(sel, id);
    }

    public int[] getSavedHairs() {
        return getPlayer().getSavedHairs();
    }

    public int getSavedHair(int sel) {
        return getPlayer().getSavedHair(sel);
    }

    public void setSavedHair(int sel, int id) {
        getPlayer().setSavedHair(sel, id);
    }
    
     public int 获取推广人ID() {
        int 推广人ID = 0;
        try {
            int cid = getPlayer().getAccountID();
            Connection con = DatabaseConnection.getConnection();
            ResultSet rs;
            try (PreparedStatement limitCheck = con.prepareStatement("SELECT * FROM accounts WHERE id=" + cid + "")) {
                rs = limitCheck.executeQuery();
                if (rs.next()) {
                    推广人ID = rs.getInt("推广人ID");
                }
            }
            rs.close();
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
        return 推广人ID;
    }

    public void 写入推广人ID(int slot) {
        try {
            int cid = getPlayer().getAccountID();
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET 推广人ID = " + slot + " WHERE id = " + cid + "");
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
    }

    public int 获取推广值() {
        int 推广值 = 0;
        try {
            int cid = getPlayer().getAccountID();
            Connection con = DatabaseConnection.getConnection();
            ResultSet rs;
            try (PreparedStatement limitCheck = con.prepareStatement("SELECT * FROM accounts WHERE id=" + cid + "")) {
                rs = limitCheck.executeQuery();
                if (rs.next()) {
                    推广值 = rs.getInt("推广值");
                }
            }
            rs.close();
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
        return 推广值;
    }

    public void 写入推广值(int slot) {
        try {
            int cid = 获取推广人ID();
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET 推广值 = 推广值 + " + slot + " WHERE id = " + cid + "");
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
    }

    public void 更改推广值(int slot) {
        try {
            int cid = getPlayer().getAccountID();
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET 推广值 = 推广值+" + slot + " WHERE id = " + cid + "");
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
    }
    
     public String getServerName() {
        //return MapleParty.开服名字;//var MC = cm.etServerName();
        return ServerConfig.SERVERNAME;
    }
    
    public String 开服名字() {//取服务器名字
        return c.getChannelServer().getServerName();
    }
    
    public String 显示物品(int a) {
        String data = "";
        data = "#v" + a + "# #b#z" + a + "##k";
        return data;
    }
    
    public void 刷新状态() {
        c.getPlayer().getClient().getSession().write(MaplePacketCreator.getCharInfo(c.getPlayer()));
        c.getPlayer().getMap().removePlayer(c.getPlayer());
        c.getPlayer().getMap().addPlayer(c.getPlayer());
        c.getSession().write(MaplePacketCreator.enableActions());
    }

    public void 刷新地图() {
        boolean custMap = true;
        int mapid = c.getPlayer().getMapId();
        MapleMap map = custMap ? c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid) : c.getPlayer().getMap();
        if (c.getPlayer().getClient().getChannelServer().getMapFactory().destroyMap(mapid)) {
            MapleMap newMap = c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid);
            MaplePortal newPor = newMap.getPortal(0);
            LinkedHashSet<MapleCharacter> mcs = new LinkedHashSet<>(map.getCharacters()); //菱形推断好点
            outerLoop:
            for (MapleCharacter m : mcs) {
                for (int x = 0; x < 5; x++) {
                    try {
                        m.changeMap(newMap, newPor);
                        continue outerLoop;
                    } catch (Throwable t) {
                    }
                }
            }
        }
    }
    
    public void 说明文字(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 00", (byte) 0));
        lastMsg = 0;
    }
    
    public void 是否说明文字(String text) {
        if (lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) { // will dc otherwise!
            sendSimple(text);
            return;
        }
        c.sendPacket(MaplePacketCreator.getNPCTalk(npc, (byte) 1, text, "", (byte) 0));
        lastMsg = 1;
    }
    
    public int 在线人数() {
        int count = 0;
        for (ChannelServer chl : ChannelServer.getAllInstances()) {
            count += chl.getPlayerStorage().getAllCharacters().size();
        }
        return count;
    }
    
    public void 打开网页(String web) {//打开网址
        this.c.sendPacket(MaplePacketCreator.openWeb(web));
    }
    
    public void 给技能(final int action, final byte level, final byte masterlevel) {
        c.getPlayer().changeSkillLevel(SkillFactory.getSkill(action), level, masterlevel);
    }
    
    public void 对话结束() {
        NPCScriptManager.getInstance().dispose(c);
    }
    
    public int 判断豆豆数量() {//判断豆豆
        return getClient().getPlayer().getBeans();
    }

   

    public void 给豆豆(int s) {//给豆豆
        getPlayer().gainBeans(s);
        //c.sendPacket(MaplePacketCreator.updateBeans(c.getPlayer().getId(), s));
        c.sendPacket(MaplePacketCreator.updateBeans(this.c.getPlayer()));
    }

    public void 收豆豆(int s) {//给豆豆
        getPlayer().gainBeans(-s);
        c.sendPacket(MaplePacketCreator.updateBeans(this.c.getPlayer()));
    }

    //public int getHyPay(int type) {//判断HYPAY
    //    return getPlayer().getHyPay(type);
   // }
    
    public void 强化加卷次数(int upgr) {
        Equip item = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) 1).copy();
        item.setUpgradeSlots((byte) (item.getUpgradeSlots() + upgr));
        MapleInventoryManipulator.removeFromSlot(getC(), MapleInventoryType.EQUIP, (short) 1, (short) 1, true);
        MapleInventoryManipulator.addFromDrop(getChar().getClient(), item, false);
    }
    
     public void gainEquiPproperty(int upgr, int watk, int matk, int str, int dex, int Int, int luk, int hp, int mp, int acc, int avoid) {
        Equip item = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) 1).copy();
        item.setUpgradeSlots((byte) (item.getUpgradeSlots() + upgr));
        item.setWatk((short) (item.getWatk() + watk));
        item.setMatk((short) (item.getMatk() + matk));
        item.setStr((short) (item.getStr() + str));
        item.setDex((short) (item.getDex() + dex));
        item.setInt((short) (item.getInt() + Int));
        item.setLuk((short) (item.getLuk() + luk));
        item.setHp((short) (item.getHp() + hp));
        item.setMp((short) (item.getMp() + mp));
        item.setAcc((byte) (item.getAcc() + acc));
        item.setAvoid((byte) (item.getAvoid() + avoid));
        MapleInventoryManipulator.removeFromSlot(getC(), MapleInventoryType.EQUIP, (short) 1, (short) 1, true);
        MapleInventoryManipulator.addFromDrop(getChar().getClient(), item, false);
    }

    public String 显示装备属性() {
        StringBuilder name = new StringBuilder();
        Equip item = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) 1).copy();
        if (item.getUpgradeSlots() > 0) {
            name.append("升级次数:#b" + item.getUpgradeSlots() + "#k\r\n");
        }
        if (item.getWatk() > 0) {
            name.append("物理攻击力:#b" + item.getWatk() + "#k\r\n");
        }
        if (item.getMatk() > 0) {
            name.append("魔法攻击力:#b" + item.getMatk() + "#k\r\n");
        }
        if (item.getWdef() > 0) {
            name.append("物理防御力:#b" + item.getWdef() + "#k\r\n");
        }
        if (item.getMdef() > 0) {
            name.append("魔法防御力:#b" + item.getMdef() + "#k\r\n");
        }
        if (item.getStr() > 0) {
            name.append("力量:#b" + item.getStr() + "#k\r\n");
        }
        if (item.getDex() > 0) {
            name.append("敏捷:#b" + item.getDex() + "#k\r\n");
        }
        if (item.getLuk() > 0) {
            name.append("运气:#b" + item.getLuk() + "#k\r\n");
        }
        if (item.getInt() > 0) {
            name.append("智力:#b" + item.getInt() + "#k\r\n");
        }
        if (item.getHp() > 0) {
            name.append("HP:#b" + item.getHp() + "#k\r\n");
        }
        if (item.getMp() > 0) {
            name.append("MP:#b" + item.getMp() + "#k\r\n");
        }
        if (item.getAcc() > 0) {
            name.append("命中率:#b" + item.getAcc() + "#k\r\n");
        }
        if (item.getAvoid() > 0) {
            name.append("闪避率:#b" + item.getAvoid() + "#k\r\n");
        }
        if (item.getSpeed() > 0) {
            name.append("移动速度:#b" + item.getSpeed() + "#k\r\n");
        }
        return name.toString();
    }

   // public void 获取装备栏物品代码() {
   //     c.getPlayer().dropMessage(5, "" + ((Equip) c.getPlayer().getInventory(MapleInventoryType.装备栏).getItem((short) 1)) + "");
   // }

    //部位。属性，成功率，值
    public void 强化穿戴装备(int aa, int bb, int cc, int dd) {
        Equip item = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) aa).copy();

    }
    
    public void 打开商店(int id) {//打开商店
        MapleShopFactory.getInstance().getShop(id).sendShop(c);
    }
    
    public int getLevel() {//判断等级
        return getPlayer().getLevel();
    }

    public void 设置等级(int s) {//判断等级
        c.getPlayer().setLevel((short) s);
    }

    public int 判断等级() {//判断等级
        return getPlayer().getLevel();
    }

    public void 刷新() {//刷新
        MapleCharacter player = c.getPlayer();
        c.sendPacket(MaplePacketCreator.getCharInfo(player));
        player.getMap().removePlayer(player);
        player.getMap().addPlayer(player);
    }
    
    public int 判断金币() {//判断金币
        return getPlayer().getMeso();
    }

    public int 判断角色ID() {//判断金币
        return c.getPlayer().getId();
    }

    public int 判断点券() {
        return c.getPlayer().getCSPoints(1);
    }

    public int 判断抵用券() {
        return c.getPlayer().getCSPoints(2);
    }

    public int 判断声望() {
        return getPlayer().getCurrentRep();
    }

    public int 判断学院() {
        return getPlayer().getFamilyId();
    }

    public int 判断师傅() {
        return getPlayer().getSeniorId();
    }

    public void 给声望(int s) {
        c.getPlayer().setCurrentRep(s);
    }

    public void 组队人数() {
        if (getParty() != null) {
            c.getPlayer().getParty().getMembers().size();
        }
    }

    public int 判断经验() {
        return c.getPlayer().getExp();
    }

    public int 判断当前地图怪物数量() {
        return c.getPlayer().getMap().getAllMonstersThreadsafe().size();
    }

    public int 判断指定地图怪物数量(int a) {
        return getMap(a).getAllMonstersThreadsafe().size();
    }

    public int 判断当前地图玩家数量() {
        return c.getPlayer().getMap().getCharactersSize();
    }

    public int 随机数(int a) {
        return (int) Math.ceil(Math.random() * a);
    }
    
    public int 获取当前星期() {

        return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);

    }
    

    public void 公告(int lx, String msg) {
        switch (lx) {
            case 1:
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(11, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 2:
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(12, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 3:
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(3, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
        }
    }
    
     //喇叭
    public void 通知(String text) {
        World.Broadcast.broadcastMessage(MaplePacketCreator.serverNotice(6, text));
    }
    
    /*
            case 1: // 弹窗
            case 2: // 粉蓝色底蓝色字 可用
            case 3: // 粉紫色底紫色字(带频道标记) 可用
            case 5: // 无底色粉红字 可用
            case 6: // 无底色粉蓝字 可用
            case 9: // 无底色黄色字 高亮    可用
            case 11:// 带爱心的白色底粉红字 不可用
            case 12:// 带电话带爱心的白色底粉红字 可用
    
    */
    
    public void 喇叭(int lx, String msg) {
        switch (lx) {
            case 1:// 带爱心的白色底粉红字 不可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(11, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 2:// 带电话带爱心的白色底粉红字 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(12, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 3://粉紫色底紫色字(带频道标记) 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(3, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 4:// 无底色黄色字 高亮    可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(9, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                break;
            case 5:// 粉蓝色底蓝色字 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(2, this.c.getChannel(), "["+ServerConfig.SERVERNAME+"] : " + msg));
                
        }
    }
    
     public void 组队征集喇叭(int lx, String msg) {
        switch (lx) {
            case 1:// 带爱心的白色底粉红字 不可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(11, this.c.getChannel(), "[组队征集令]  : " + msg));
                break;
            case 2:// 带电话带爱心的白色底粉红字 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(12, this.c.getChannel(), "[组队征集令] : " + msg));
                break;
            case 3://粉紫色底紫色字(带频道标记) 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(3, this.c.getChannel(), "[组队征集令] :" + msg));
                break;
            case 4:// 无底色黄色字 高亮    可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(9, this.c.getChannel(), "[组队征集令] : " + msg));
                break;
            case 5:// 粉蓝色底蓝色字 可用
                World.Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(2, this.c.getChannel(), "[组队征集令] :" + msg));
                
        }
    }
     
     public static String SN取出售(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? && channel = 1");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取库存(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 2");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取折扣(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 3");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取限购(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 4");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取类型(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 5");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static int 角色名字取ID(String id) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT id as DATA FROM characters WHERE name = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色名字取ID出错 - 数据库查询失败：" + Ex);
        }

        return data;
    }
    public static String 角色ID取名字(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM characters WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }
    public static int 角色名字取账号ID(String id) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid as DATA FROM characters WHERE name = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色名字取ID出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }
    public static String IP取账号(String id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM accounts WHERE SessionIP = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    data = rs.getString("DATA");
                    return data;
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String MAC取账号(String id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM accounts WHERE macs = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }
    public static String 账号ID取账号(String id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM accounts WHERE id = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色名字取ID出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 账号ID取在线(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT loggedin as DATA FROM accounts WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色名字取ID出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 角色名字取等级(String id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT level as DATA FROM characters WHERE name = ?");
            ps.setString(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色名字取ID出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String 物品获取掉落怪物(int itemid) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT dropperid as DATA FROM drop_data WHERE itemid = ?");
            ps.setInt(1, itemid);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取物品获取掉落怪物出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }
    
    public static String 获取家族名称(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }
    
        public static String 获取最高等级玩家名字() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `level` FROM characters WHERE gm = 0 ORDER BY `level` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("level");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }
    
    public int 角色ID取雇佣数据(int id) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT cid as DATA FROM hire WHERE cid = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("角色名字取账号ID、出错");
        }
        return data;
    }    
     
    public static int 角色ID取账号ID(int id) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid as DATA FROM characters WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("角色名字取账号ID、出错");
        }
        return data;
    }
    
    public static String 账号ID取绑定QQ(int id) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT qq as DATA FROM accounts WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("账号ID取账号、出错");
        }
        return data;
    }
    
    //新增变量
    public int getzs() {
        return getPlayer().getzs();
    }

    public void setzs(int set) {
        getPlayer().setzs(set);
    }
    
    public void gainzs(int gain) {
        getPlayer().gainzs(gain);
    }
    
    public int getjf() {
        return getPlayer().getjf();
    }

    public void setjf(int set) {
        getPlayer().setjf(set);
    }
    
    public void gainjf(int gain) {
        getPlayer().gainjf(gain);
    }
    
    public int getzdjf() {
        return getPlayer().getzdjf();
    }

    public void setzdjf(int set) {
        getPlayer().setzdjf(set);
    }
    
    public void gainzdjf(int gain) {
        getPlayer().gainzdjf(gain);
    }
    
    public int getrwjf() {
        return getPlayer().getrwjf();
    }

    public void setrwjf(int set) {
        getPlayer().setrwjf(set);
    }
    
    public void gainrwjf(int gain) {
        getPlayer().gainrwjf(gain);
    }
    
    public int getcz() {
        return getPlayer().getcz();
    }

    public void setcz(int set) {
        getPlayer().setcz(set);
    }
    
    public void gaincz(int gain) {
        getPlayer().gaincz(gain);
    }
    
    public int getdy() {
        return getPlayer().getdy();
    }

    public void setdy(int set) {
        getPlayer().setdy(set);
    }
    
    public void gaindy(int gain) {
        getPlayer().gaindy(gain);
    }
    
    public int getrmb() {
        return getPlayer().getrmb();
    }

    public void setrmb(int set) {
        getPlayer().setrmb(set);
    }
    
    public void gainrmb(int gain) {
        getPlayer().gainrmb(gain);
    }
    
    public int getyb() {
        return getPlayer().getyb();
    }

    public void setyb(int set) {
        getPlayer().setyb(set);
    }
    
    public void gainyb(int gain) {
        getPlayer().gainyb(gain);
    }
    //角色积分
    public int getplayerPoints() {
        return getPlayer().getplayerPoints();
    }

    public void setplayerPoints(int set) {
        getPlayer().setplayerPoints(set);
    }
    
    public void gainplayerPoints(int gain) {
        getPlayer().gainplayerPoints(gain);
    }
    //活力值
    public int getplayerEnergy() {
        return getPlayer().getplayerEnergy();
    }

    public void setplayerEnergy(int set) {
        getPlayer().setplayerEnergy(set);
    }
    
    public void gainplayerEnergy(int gain) {
        getPlayer().gainplayerEnergy(gain);
    }
    
    public int getjf1() {
        return getPlayer().getjf1();
    }

    public void setjf1(int set) {
        getPlayer().setjf1(set);
    }
    
    public void gainjf1(int gain) {
        getPlayer().gainjf1(gain);
    }
    
    public int getjf2() {
        return getPlayer().getjf2();
    }

    public void setjf2(int set) {
        getPlayer().setjf2(set);
    }
    
    public void gainjf2(int gain) {
        getPlayer().gainjf2(gain);
    }
    
    public int getjf3() {
        return getPlayer().getjf3();
    }

    public void setjf3(int set) {
        getPlayer().setjf3(set);
    }
    
    public void gainjf3(int gain) {
        getPlayer().gainjf3(gain);
    }
    
    public int getjf4() {
        return getPlayer().getjf4();
    }

    public void setjf4(int set) {
        getPlayer().setjf4(set);
    }
    
    public void gainjf4(int gain) {
        getPlayer().gainjf4(gain);
    }
    
    public int getjf5() {
        return getPlayer().getjf5();
    }

    public void setjf5(int set) {
        getPlayer().setjf5(set);
    }
    
    public void gainjf5(int gain) {
        getPlayer().gainjf5(gain);
    }
    
    public int getjf6() {
        return getPlayer().getjf6();
    }

    public void setjf6(int set) {
        getPlayer().setjf6(set);
    }
    
    public void gainjf6(int gain) {
        getPlayer().gainjf6(gain);
    }
    
    public int getjf7() {
        return getPlayer().getjf7();
    }

    public void setjf7(int set) {
        getPlayer().setjf7(set);
    }
    
    public void gainjf7(int gain) {
        getPlayer().gainjf7(gain);
    }
    
    public int getjf8() {
        return getPlayer().getjf8();
    }

    public void setjf8(int set) {
        getPlayer().setjf8(set);
    }
    
    public void gainjf8(int gain) {
        getPlayer().gainjf8(gain);
    }
    
    public int getjf9() {
        return getPlayer().getjf9();
    }

    public void setjf9(int set) {
        getPlayer().setjf9(set);
    }
    
    public void gainjf9(int gain) {
        getPlayer().gainjf9(gain);
    }
    
    public int getjf10() {
        return getPlayer().getjf10();
    }

    public void setjf10(int set) {
        getPlayer().setjf10(set);
    }
    
    public void gainjf10(int gain) {
        getPlayer().gainjf10(gain);
    }
    
    
    
    //新增
    public void 个人存档() {
        c.getPlayer().saveToDB(false, false);
    }

    public void 角色ID() {
        c.getPlayer().getId();
    }
    
    public void 全服存档() {
        try {
            for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharacters()) {
                    if (chr == null) {
                        continue;
                    }
                    chr.saveToDB(false, false);
                }
            }
        } catch (Exception e) {
        }
    }

    public static void 商城物品(final int id, final int key) throws SQLException {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = null;
            ps = con.prepareStatement("INSERT INTO cashshop_modified_items (itemid, meso) VALUES (?, ?)");
            //写ID
            ps.setInt(1, id);
            //写类型
            ps.setInt(2, key);
            //写建委
        } catch (SQLException ex) {
            Logger.getLogger(NPCConversationManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void 键盘上技能(final int id, final int key, final int type, final int action, final byte level, final byte masterlevel) throws SQLException {
        //给予技能先
        c.getPlayer().changeSkillLevel(SkillFactory.getSkill(action), level, masterlevel);
        c.getPlayer().dropMessage(1, "<提示>\r\n5秒后你会自动下线，请1分钟后再次登陆。");
        //存档
        c.getPlayer().saveToDB(false, false);
        new Thread() {
            @Override
            public void run() {
                try {
                    //5秒后断开玩家链接
                    Thread.sleep(1000 * 5);
                    c.getPlayer().getClient().getSession().close();
                    //10秒后开始执行上技能指令
                    Thread.sleep(1000 * 10);
                    Connection con = DatabaseConnection.getConnection();
                    PreparedStatement ps = null;
                    ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
                    //写ID
                    ps.setInt(1, id);
                    //写类型
                    ps.setInt(2, key);
                    //写建委
                    ps.setInt(3, type);
                    //写代码
                    ps.setInt(4, action);
                    ps.execute();
                } catch (InterruptedException e) {
                } catch (SQLException ex) {
                    Logger.getLogger(NPCConversationManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }.start();
    }

    public void 删除角色(int id) {
        PreparedStatement ps1 = null;
        try {
            ps1 = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM characters WHERE id = ?");
        } catch (SQLException ex) {

        }
        String sqlstr = " delete from characters where id =" + id + "";
        try {
            ps1.executeUpdate(sqlstr);
            c.getPlayer().dropMessage(1, "角色删除成功。");
        } catch (SQLException ex) {
        }
    }

    public void 开始计时() {

        System.currentTimeMillis();
    }
    
     public void 剑客排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().剑客()));
    }

    public void 勇士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().勇士()));
    }

    public void 英雄排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().英雄()));
    }

    public void 准骑士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().准骑士()));
    }

    public void 骑士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().骑士()));
    }

    public void 圣骑士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().圣骑士()));
    }

    public void 枪战士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().枪战士()));
    }

    public void 龙骑士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().龙骑士()));
    }

    public void 黑骑士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().黑骑士()));
    }

    public void 火毒法师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().火毒法师()));
    }

    public void 火毒巫师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().火毒巫师()));
    }

    public void 火毒魔导师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().火毒魔导师()));
    }

    public void 冰雷法师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().冰雷法师()));
    }

    public void 冰雷巫师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().冰雷巫师()));
    }

    public void 冰雷魔导师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().冰雷魔导师()));
    }

    public void 牧师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().牧师()));
    }

    public void 祭师排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().祭师()));
    }

    public void 主教排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().主教()));
    }

    public void 猎人排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().猎人()));
    }

    public void 射手排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().射手()));
    }

    public void 神射手排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().神射手()));
    }

    public void 弩弓手排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().弩弓手()));
    }

    public void 游侠排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().游侠()));
    }

    public void 箭神排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().箭神()));
    }

    public void 刺客排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().刺客()));
    }

    public void 无影人排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().无影人()));
    }

    public void 隐士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().隐士()));
    }

    public void 侠客排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().侠客()));
    }

    public void 独行客排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().独行客()));
    }

    public void 侠盗排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().侠盗()));
    }

    public void 拳手排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().拳手()));
    }

    public void 斗士排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().斗士()));
    }

    public void 冲锋队长排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().冲锋队长()));
    }

    public void 火枪手排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().火枪手()));
    }

    public void 大副排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().大副()));
    }

    public void 船长排行榜() {//等级榜
        c.sendPacket(MaplePacketCreator.showlevelRanks(npc, MapleGuildRanking.getInstance().船长()));
    }

    //1点卷/2抵用/3金币/4经验
    public int 给全服发点卷(int 数量, int 类型) {
        int count = 0;

        try {
            if (数量 <= 0 || 类型 <= 0) {
                return 0;
            }

            if (类型 == 1 || 类型 == 2) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        mch.modifyCSPoints(类型, 数量);
                        String cash = null;
                        if (类型 == 1) {
                            cash = "点卷";
                        } else if (类型 == 2) {
                            cash = "抵用卷";
                        }
                        //mch.startMapEffect("管理员发放" + 数量 + cash + "给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 3) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        // mch.modifyCSPoints(类型, 数量);
                        mch.gainMeso(数量, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "冒险币给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 4) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        mch.gainExp(数量, true, false, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "经验给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给全服发点卷出错：" + e.getMessage());
        }

        return count;
    }

//1点卷/2抵用/3金币/4经验
    public int 给当前地图发点卷(int 数量, int 类型) {
        int count = 0;
        int mapId = c.getPlayer().getMapId();
        try {
            if (数量 <= 0 || 类型 <= 0) {
                return 0;
            }

            if (类型 == 1 || 类型 == 2) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        if (mch.getMapId() != mapId) {
                            continue;
                        }
                        mch.modifyCSPoints(类型, 数量);
                        String cash = null;
                        if (类型 == 1) {
                            cash = "点卷";
                        } else if (类型 == 2) {
                            cash = "抵用卷";
                        }
                        //mch.startMapEffect("管理员发放" + 数量 + cash + "给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 3) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        if (mch.getMapId() != mapId) {
                            continue;
                        }
                        mch.gainMeso(数量, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "冒险币给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 4) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        if (mch.getMapId() != mapId) {
                            continue;
                        }
                        mch.gainExp(数量, true, false, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "经验给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给当前地图发点卷出错：" + e.getMessage());
        }

        return count;
    }

//1点卷/2抵用/3金币/4经验
    public int 给当前频道发点卷(int 数量, int 类型) {
        int count = 0;
        int chlId = c.getPlayer().getMap().getChannel();

        try {
            if (数量 <= 0 || 类型 <= 0) {
                return 0;
            }
            if (类型 == 1 || 类型 == 2) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    if (cserv1.getChannel() != chlId) {
                        continue;
                    }
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        mch.modifyCSPoints(类型, 数量);
                        String cash = null;
                        if (类型 == 1) {
                            cash = "点卷";
                        } else if (类型 == 2) {
                            cash = "抵用卷";
                        }
                        //mch.startMapEffect("管理员发放" + 数量 + cash + "给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 3) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    if (cserv1.getChannel() != chlId) {
                        continue;
                    }
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        // mch.modifyCSPoints(类型, 数量);
                        mch.gainMeso(数量, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "冒险币给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            } else if (类型 == 4) {
                for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                    if (cserv1.getChannel() != chlId) {
                        continue;
                    }
                    for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                        mch.gainExp(数量, true, false, true);
                        //mch.startMapEffect("管理员发放" + 数量 + "经验给在线的所有玩家！快感谢管理员吧！", 5121009);
                        count++;
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给当前频道发点卷出错：" + e.getMessage());
        }

        return count;
    }
    
    public int 给全服发物品(int 物品ID, int 数量, int 力量, int 敏捷, int 智力, int 运气, int HP, int MP, int 可加卷次数, String 制作人名字, int 给予时间, String 是否可以交易, int 攻击力, int 魔法力, int 物理防御, int 魔法防御) {
        int count = 0;

        try {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            MapleInventoryType type = GameConstants.getInventoryType(物品ID);

            for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                    if (数量 >= 0) {
                        if (!MapleInventoryManipulator.checkSpace(mch.getClient(), 物品ID, 数量, "")) {
                            return 0;
                        }
                        if (type.equals(MapleInventoryType.EQUIP) && !GameConstants.isThrowingStar(物品ID) && !GameConstants.isBullet(物品ID)
                                || type.equals(MapleInventoryType.CASH) && 物品ID >= 5000000 && 物品ID <= 5000100) {
                            final Equip item = (Equip) (ii.getEquipById(物品ID));
                            if (ii.isCash(物品ID)) {
                                item.setUniqueId(1);
                            }
                            if (力量 > 0 && 力量 <= 32767) {
                                item.setStr((short) (力量));
                            }
                            if (敏捷 > 0 && 敏捷 <= 32767) {
                                item.setDex((short) (敏捷));
                            }
                            if (智力 > 0 && 智力 <= 32767) {
                                item.setInt((short) (智力));
                            }
                            if (运气 > 0 && 运气 <= 32767) {
                                item.setLuk((short) (运气));
                            }
                            if (攻击力 > 0 && 攻击力 <= 32767) {
                                item.setWatk((short) (攻击力));
                            }
                            if (魔法力 > 0 && 魔法力 <= 32767) {
                                item.setMatk((short) (魔法力));
                            }
                            if (物理防御 > 0 && 物理防御 <= 32767) {
                                item.setWdef((short) (物理防御));
                            }
                            if (魔法防御 > 0 && 魔法防御 <= 32767) {
                                item.setMdef((short) (魔法防御));
                            }
                            if (HP > 0 && HP <= 30000) {
                                item.setHp((short) (HP));
                            }
                            if (MP > 0 && MP <= 30000) {
                                item.setMp((short) (MP));
                            }
                            if ("可以交易".equals(是否可以交易)) {
                                byte flag = item.getFlag();
                                if (item.getType() == MapleInventoryType.EQUIP.getType()) {
                                    flag |= ItemFlag.KARMA_EQ.getValue();
                                } else {
                                    flag |= ItemFlag.KARMA_USE.getValue();
                                }
                                item.setFlag(flag);
                            }
                            if (给予时间 > 0) {
                                item.setExpiration(System.currentTimeMillis() + (给予时间 * 24 * 60 * 60 * 1000));
                            }
                            if (可加卷次数 > 0) {
                                item.setUpgradeSlots((byte) (可加卷次数));
                            }
                            if (制作人名字 != null) {
                                item.setOwner(制作人名字);
                            }
                            final String name = ii.getName(物品ID);
                            if (物品ID / 10000 == 114 && name != null && name.length() > 0) { //medal
                                final String msg = "你已获得称号 <" + name + ">";
                                mch.getClient().getPlayer().dropMessage(5, msg);
                            }
                            MapleInventoryManipulator.addbyItem(mch.getClient(), item.copy());
                        } else {
                            MapleInventoryManipulator.addById(mch.getClient(), 物品ID, (short) 数量, "", null, 给予时间, (byte) 0);
                        }
                    } else {
                        MapleInventoryManipulator.removeById(mch.getClient(), GameConstants.getInventoryType(物品ID), 物品ID, -数量, true, false);
                    }
                    mch.getClient().sendPacket(MaplePacketCreator.getShowItemGain(物品ID, (short) 数量, true));

                    count++;
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给全服发物品出错：" + e.getMessage());
        }

        return count;
    }

    public int 给当前地图发物品(int 物品ID, int 数量, int 力量, int 敏捷, int 智力, int 运气, int HP, int MP, int 可加卷次数, String 制作人名字, int 给予时间, String 是否可以交易, int 攻击力, int 魔法力, int 物理防御, int 魔法防御) {
        int count = 0;
        int mapId = c.getPlayer().getMapId();

        try {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            MapleInventoryType type = GameConstants.getInventoryType(物品ID);

            for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                    if (mch.getMapId() != mapId) {
                        continue;
                    }
                    if (数量 >= 0) {
                        if (!MapleInventoryManipulator.checkSpace(mch.getClient(), 物品ID, 数量, "")) {
                            return 0;
                        }
                        if (type.equals(MapleInventoryType.EQUIP) && !GameConstants.isThrowingStar(物品ID) && !GameConstants.isBullet(物品ID)
                                || type.equals(MapleInventoryType.CASH) && 物品ID >= 5000000 && 物品ID <= 5000100) {
                            final Equip item = (Equip) (ii.getEquipById(物品ID));
                            if (ii.isCash(物品ID)) {
                                item.setUniqueId(1);
                            }
                            if (力量 > 0 && 力量 <= 32767) {
                                item.setStr((short) (力量));
                            }
                            if (敏捷 > 0 && 敏捷 <= 32767) {
                                item.setDex((short) (敏捷));
                            }
                            if (智力 > 0 && 智力 <= 32767) {
                                item.setInt((short) (智力));
                            }
                            if (运气 > 0 && 运气 <= 32767) {
                                item.setLuk((short) (运气));
                            }
                            if (攻击力 > 0 && 攻击力 <= 32767) {
                                item.setWatk((short) (攻击力));
                            }
                            if (魔法力 > 0 && 魔法力 <= 32767) {
                                item.setMatk((short) (魔法力));
                            }
                            if (物理防御 > 0 && 物理防御 <= 32767) {
                                item.setWdef((short) (物理防御));
                            }
                            if (魔法防御 > 0 && 魔法防御 <= 32767) {
                                item.setMdef((short) (魔法防御));
                            }
                            if (HP > 0 && HP <= 30000) {
                                item.setHp((short) (HP));
                            }
                            if (MP > 0 && MP <= 30000) {
                                item.setMp((short) (MP));
                            }
                            if ("可以交易".equals(是否可以交易)) {
                                byte flag = item.getFlag();
                                if (item.getType() == MapleInventoryType.EQUIP.getType()) {
                                    flag |= ItemFlag.KARMA_EQ.getValue();
                                } else {
                                    flag |= ItemFlag.KARMA_USE.getValue();
                                }
                                item.setFlag(flag);
                            }
                            if (给予时间 > 0) {
                                item.setExpiration(System.currentTimeMillis() + (给予时间 * 24 * 60 * 60 * 1000));
                            }
                            if (可加卷次数 > 0) {
                                item.setUpgradeSlots((byte) (可加卷次数));
                            }
                            if (制作人名字 != null) {
                                item.setOwner(制作人名字);
                            }
                            final String name = ii.getName(物品ID);
                            if (物品ID / 10000 == 114 && name != null && name.length() > 0) { //medal
                                final String msg = "你已获得称号 <" + name + ">";
                                mch.getClient().getPlayer().dropMessage(5, msg);
                            }
                            MapleInventoryManipulator.addbyItem(mch.getClient(), item.copy());
                        } else {
                            MapleInventoryManipulator.addById(mch.getClient(), 物品ID, (short) 数量, "", null, 给予时间, (byte) 0);
                        }
                    } else {
                        MapleInventoryManipulator.removeById(mch.getClient(), GameConstants.getInventoryType(物品ID), 物品ID, -数量, true, false);
                    }
                    mch.getClient().sendPacket(MaplePacketCreator.getShowItemGain(物品ID, (short) 数量, true));

                    count++;
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给当前地图发物品出错：" + e.getMessage());
        }

        return count;
    }

    public int 给当前频道发物品(int 物品ID, int 数量, int 力量, int 敏捷, int 智力, int 运气, int HP, int MP, int 可加卷次数, String 制作人名字, int 给予时间, String 是否可以交易, int 攻击力, int 魔法力, int 物理防御, int 魔法防御) {
        int count = 0;
        int chlId = c.getPlayer().getMap().getChannel();

        try {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            MapleInventoryType type = GameConstants.getInventoryType(物品ID);

            for (ChannelServer cserv1 : ChannelServer.getAllInstances()) {
                if (cserv1.getChannel() != chlId) {
                    continue;
                }
                for (MapleCharacter mch : cserv1.getPlayerStorage().getAllCharacters()) {
                    if (数量 >= 0) {
                        if (!MapleInventoryManipulator.checkSpace(mch.getClient(), 物品ID, 数量, "")) {
                            return 0;
                        }
                        if (type.equals(MapleInventoryType.EQUIP) && !GameConstants.isThrowingStar(物品ID) && !GameConstants.isBullet(物品ID)
                                || type.equals(MapleInventoryType.CASH) && 物品ID >= 5000000 && 物品ID <= 5000100) {
                            final Equip item = (Equip) (ii.getEquipById(物品ID));
                            if (ii.isCash(物品ID)) {
                                item.setUniqueId(1);
                            }
                            if (力量 > 0 && 力量 <= 32767) {
                                item.setStr((short) (力量));
                            }
                            if (敏捷 > 0 && 敏捷 <= 32767) {
                                item.setDex((short) (敏捷));
                            }
                            if (智力 > 0 && 智力 <= 32767) {
                                item.setInt((short) (智力));
                            }
                            if (运气 > 0 && 运气 <= 32767) {
                                item.setLuk((short) (运气));
                            }
                            if (攻击力 > 0 && 攻击力 <= 32767) {
                                item.setWatk((short) (攻击力));
                            }
                            if (魔法力 > 0 && 魔法力 <= 32767) {
                                item.setMatk((short) (魔法力));
                            }
                            if (物理防御 > 0 && 物理防御 <= 32767) {
                                item.setWdef((short) (物理防御));
                            }
                            if (魔法防御 > 0 && 魔法防御 <= 32767) {
                                item.setMdef((short) (魔法防御));
                            }
                            if (HP > 0 && HP <= 30000) {
                                item.setHp((short) (HP));
                            }
                            if (MP > 0 && MP <= 30000) {
                                item.setMp((short) (MP));
                            }
                            if ("可以交易".equals(是否可以交易)) {
                                byte flag = item.getFlag();
                                if (item.getType() == MapleInventoryType.EQUIP.getType()) {
                                    flag |= ItemFlag.KARMA_EQ.getValue();
                                } else {
                                    flag |= ItemFlag.KARMA_USE.getValue();
                                }
                                item.setFlag(flag);
                            }
                            if (给予时间 > 0) {
                                item.setExpiration(System.currentTimeMillis() + (给予时间 * 24 * 60 * 60 * 1000));
                            }
                            if (可加卷次数 > 0) {
                                item.setUpgradeSlots((byte) (可加卷次数));
                            }
                            if (制作人名字 != null) {
                                item.setOwner(制作人名字);
                            }
                            final String name = ii.getName(物品ID);
                            if (物品ID / 10000 == 114 && name != null && name.length() > 0) { //medal
                                final String msg = "你已获得称号 <" + name + ">";
                                mch.getClient().getPlayer().dropMessage(5, msg);
                            }
                            MapleInventoryManipulator.addbyItem(mch.getClient(), item.copy());
                        } else {
                            MapleInventoryManipulator.addById(mch.getClient(), 物品ID, (short) 数量, "", null, 给予时间, (byte) 0);
                        }
                    } else {
                        MapleInventoryManipulator.removeById(mch.getClient(), GameConstants.getInventoryType(物品ID), 物品ID, -数量, true, false);
                    }
                    mch.getClient().sendPacket(MaplePacketCreator.getShowItemGain(物品ID, (short) 数量, true));

                    count++;
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给当前频道发物品出错：" + e.getMessage());
        }

        return count;
    }
    
     public int 传送当前地图所有人到指定地图(int destMapId, Boolean includeSelf) {
        int count = 0;
        int myMapId = c.getPlayer().getMapId();
        int myId = c.getPlayer().getId();

        try {
            final MapleMap tomap = getMapFactory().getMap(destMapId);
            final MapleMap frommap = getMapFactory().getMap(myMapId);
            List<MapleCharacter> list = frommap.getCharactersThreadsafe();
            if (tomap != null && frommap != null && list != null && frommap.getCharactersSize() > 0) {
                for (MapleMapObject mmo : list) {
                    MapleCharacter chr = (MapleCharacter) mmo;
                    if (chr.getId() == myId) { // 自己
                        if (includeSelf) {
                            chr.changeMap(tomap, tomap.getPortal(0));
                            count++;
                        }
                    } else {
                        chr.changeMap(tomap, tomap.getPortal(0));
                        count++;
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("传送当前地图所有人到指定地图出错：" + e.getMessage());
        }

        return count;
    }

    public int 杀死当前地图所有人(Boolean includeSelf) {
        int count = 0;
        int myMapId = c.getPlayer().getMapId();
        int myId = c.getPlayer().getId();

        try {
            final MapleMap frommap = getMapFactory().getMap(myMapId);
            List<MapleCharacter> list = frommap.getCharactersThreadsafe();
            if (frommap != null && list != null && frommap.getCharactersSize() > 0) {
                for (MapleMapObject mmo : list) {
                    if (mmo != null) {
                        MapleCharacter chr = (MapleCharacter) mmo;
                        if (chr.getId() == myId) { // 自己
                            if (includeSelf) {
                                chr.setHp(0);
                                chr.updateSingleStat(MapleStat.HP, 0);
                                count++;
                            }
                        } else {
                            chr.setHp(0);
                            chr.updateSingleStat(MapleStat.HP, 0);
                            count++;
                        }
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("杀死当前地图所有人出错：" + e.getMessage());
        }

        return count;
    }

    public int 复活当前地图所有人(Boolean includeSelf) {
        int count = 0;
        int myMapId = c.getPlayer().getMapId();
        int myId = c.getPlayer().getId();

        try {
            final MapleMap frommap = getMapFactory().getMap(myMapId);
            List<MapleCharacter> list = frommap.getCharactersThreadsafe();
            if (frommap != null && list != null && frommap.getCharactersSize() > 0) {
                for (MapleMapObject mmo : list) {
                    if (mmo != null) {
                        MapleCharacter chr = (MapleCharacter) mmo;
                        if (chr.getId() == myId) { // 自己
                            if (includeSelf) {
                                chr.getStat().setHp(chr.getStat().getMaxHp());
                                chr.updateSingleStat(MapleStat.HP, chr.getStat().getMaxHp());
                                chr.getStat().setMp(chr.getStat().getMaxMp());
                                chr.updateSingleStat(MapleStat.MP, chr.getStat().getMaxMp());
                                chr.dispelDebuffs();
                                count++;
                            }
                        } else {
                            chr.getStat().setHp(chr.getStat().getMaxHp());
                            chr.updateSingleStat(MapleStat.HP, chr.getStat().getMaxHp());
                            chr.getStat().setMp(chr.getStat().getMaxMp());
                            chr.updateSingleStat(MapleStat.MP, chr.getStat().getMaxMp());
                            chr.dispelDebuffs();
                            count++;
                        }

                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("复活当前地图所有人出错：" + e.getMessage());
        }

        return count;
    }

    public void 跟踪玩家(String charName) {
        for (ChannelServer chl : ChannelServer.getAllInstances()) {
            for (MapleCharacter chr : chl.getPlayerStorage().getAllCharacters()) {
                if (chr.getName() == charName) {
                    c.getPlayer().changeMap(chr.getMapId());
                }
            }
        }
    }
    
     public int 给指定地图发物品(int 地图ID, int 物品ID, int 数量, int 力量, int 敏捷, int 智力, int 运气, int HP, int MP, int 可加卷次数, String 制作人名字, int 给予时间, String 是否可以交易, int 攻击力, int 魔法力, int 物理防御, int 魔法防御) {
        int count = 0;

        if (地图ID < 1) {
            地图ID = c.getPlayer().getMapId();
        }

        try {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            MapleInventoryType type = GameConstants.getInventoryType(物品ID);

            final MapleMap frommap = getMapFactory().getMap(地图ID);
            List<MapleCharacter> list = frommap.getCharactersThreadsafe();
            if (list != null && frommap.getCharactersSize() > 0) {
                for (MapleMapObject mmo : list) {
                    if (mmo != null) {
                        MapleCharacter chr = (MapleCharacter) mmo;
                        if (数量 >= 0) {
                            if (!MapleInventoryManipulator.checkSpace(chr.getClient(), 物品ID, 数量, "")) {
                                return 0;
                            }
                            if (type.equals(MapleInventoryType.EQUIP) && !GameConstants.isThrowingStar(物品ID) && !GameConstants.isBullet(物品ID)
                                    || type.equals(MapleInventoryType.CASH) && 物品ID >= 5000000 && 物品ID <= 5000100) {
                                final Equip item = (Equip) (ii.getEquipById(物品ID));
                                if (ii.isCash(物品ID)) {
                                    item.setUniqueId(1);
                                }
                                if (力量 > 0 && 力量 <= 32767) {
                                    item.setStr((short) (力量));
                                }
                                if (敏捷 > 0 && 敏捷 <= 32767) {
                                    item.setDex((short) (敏捷));
                                }
                                if (智力 > 0 && 智力 <= 32767) {
                                    item.setInt((short) (智力));
                                }
                                if (运气 > 0 && 运气 <= 32767) {
                                    item.setLuk((short) (运气));
                                }
                                if (攻击力 > 0 && 攻击力 <= 32767) {
                                    item.setWatk((short) (攻击力));
                                }
                                if (魔法力 > 0 && 魔法力 <= 32767) {
                                    item.setMatk((short) (魔法力));
                                }
                                if (物理防御 > 0 && 物理防御 <= 32767) {
                                    item.setWdef((short) (物理防御));
                                }
                                if (魔法防御 > 0 && 魔法防御 <= 32767) {
                                    item.setMdef((short) (魔法防御));
                                }
                                if (HP > 0 && HP <= 30000) {
                                    item.setHp((short) (HP));
                                }
                                if (MP > 0 && MP <= 30000) {
                                    item.setMp((short) (MP));
                                }
                                if ("可以交易".equals(是否可以交易)) {
                                    byte flag = item.getFlag();
                                    if (item.getType() == MapleInventoryType.EQUIP.getType()) {
                                        flag |= ItemFlag.KARMA_EQ.getValue();
                                    } else {
                                        flag |= ItemFlag.KARMA_USE.getValue();
                                    }
                                    item.setFlag(flag);
                                }
                                if (给予时间 > 0) {
                                    item.setExpiration(System.currentTimeMillis() + (给予时间 * 24 * 60 * 60 * 1000));
                                }
                                if (可加卷次数 > 0) {
                                    item.setUpgradeSlots((byte) (可加卷次数));
                                }
                                if (制作人名字 != null) {
                                    item.setOwner(制作人名字);
                                }
                                final String name = ii.getName(物品ID);
                                if (物品ID / 10000 == 114 && name != null && name.length() > 0) { //medal
                                    final String msg = "你已获得称号 <" + name + ">";
                                    chr.dropMessage(5, msg);
                                }
                                MapleInventoryManipulator.addbyItem(chr.getClient(), item.copy());
                            } else {
                                MapleInventoryManipulator.addById(chr.getClient(), 物品ID, (short) 数量, "", null, 给予时间, (byte) 0);
                            }
                        } else {
                            MapleInventoryManipulator.removeById(chr.getClient(), GameConstants.getInventoryType(物品ID), 物品ID, -数量, true, false);
                        }
                        chr.getClient().sendPacket(MaplePacketCreator.getShowItemGain(物品ID, (short) 数量, true));

                        count++;
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给指定地图发物品出错：" + e.getMessage());
        }

        return count;
    }

    public int 给指定地图发物品(int 地图ID, int 物品ID, int 数量) {
        return 给指定地图发物品(地图ID, 物品ID, 数量, 0, 0, 0, 0, 0, 0, 0, "", 0, "", 0, 0, 0, 0);
    }

    //1点卷/2抵用/3金币/4经验
    public int 给指定地图发点卷(int 地图ID, int 数量, int 类型) {
        int count = 0;

        String name = c.getPlayer().getName();

        if (地图ID < 1) {
            地图ID = c.getPlayer().getMapId();
        }

        try {
            if (数量 <= 0 || 类型 <= 0) {
                return 0;
            }

            final MapleMap frommap = getMapFactory().getMap(地图ID);
            List<MapleCharacter> list = frommap.getCharactersThreadsafe();
            if (list != null && frommap.getCharactersSize() > 0) {
                if (类型 == 1 || 类型 == 2) {
                    for (MapleMapObject mmo : list) {
                        if (mmo != null) {
                            MapleCharacter chr = (MapleCharacter) mmo;
                            chr.modifyCSPoints(类型, 数量);
                            String cash = null;
                            if (类型 == 1) {
                                cash = "点卷";
                            } else if (类型 == 2) {
                                cash = "抵用卷";
                            }

                            //  chr.startMapEffect(name + "为你发放了" + 数量 + cash + "！", 5121009);
                            count++;
                        }
                    }
                } else if (类型 == 3) {
                    for (MapleMapObject mmo : list) {
                        if (mmo != null) {
                            MapleCharacter chr = (MapleCharacter) mmo;
                            chr.gainMeso(数量, true);
                            //  chr.startMapEffect(name + "为你发放了" + 数量 + "金币！", 5121009);
                            count++;
                        }
                    }
                } else if (类型 == 4) {
                    for (MapleMapObject mmo : list) {
                        if (mmo != null) {
                            MapleCharacter chr = (MapleCharacter) mmo;
                            chr.gainExp(数量, true, false, true);
                            //   chr.startMapEffect(name + "为你发放了" + 数量 + "经验值！", 5121009);
                            count++;
                        }
                    }
                }
            }
        } catch (Exception e) {
            c.getPlayer().dropMessage("给指定地图发点卷出错：" + e.getMessage());
        }

        return count;
    }

    public int 获取指定地图玩家数量(int mapId) {//var count = cm.获取指定地图玩家数量(910000000);
        return getMapFactory().getMap(mapId).characterSize();
    }

    public int 判断指定地图玩家数量(int mapId) {//var count = cm.获取指定地图玩家数量(910000000);
        return getMapFactory().getMap(mapId).characterSize();
    }

    public void 给指定地图发公告(int mapId, String msg, int itemId) {//cm.给指定地图发公告(910000000)
        getMapFactory().getMap(mapId).startMapEffect(msg, itemId);
    }
    
    public void 设置天气(int 天气ID) {
        if (c.getPlayer().getMap().getPermanentWeather() > 0) {
            c.getPlayer().getMap().setPermanentWeather(0);
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeMapEffect());
        } else if (!MapleItemInformationProvider.getInstance().itemExists(天气ID) || 天气ID / 10000 != 512) {
            c.getPlayer().dropMessage(5, "无效的天气ID。");
        } else {
            c.getPlayer().getMap().setPermanentWeather(天气ID);
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.startMapEffect("", 天气ID, false));
            c.getPlayer().dropMessage(5, "地图天气已启用。");
        }
    }
    
    public void 爆物开关() {
        c.getPlayer().getMap().toggleDrops();
    }

    public long 查看蓄力一击() {
        return (System.currentTimeMillis() - c.getPlayer().蓄力一击) / 10;
    }

    public void 给人气(int r) {
        c.getPlayer().addFame(r);
    }

    public void 判断人气() {
        c.getPlayer().getFame();
    }

    public void 回收地图() {
        if (判断地图(c.getPlayer().getMapId()) <= 0) {
            final int 地图 = c.getPlayer().getMapId();
            记录地图(地图);
            c.getPlayer().dropMessage(1, "回收成功，此地图将在 5 分钟后被回收。");
            new Thread() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1000 * 60 * 5);
                        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                            for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharacters()) {
                                if (chr == null) {
                                    continue;
                                }
                                if (chr.getMapId() == 地图) {
                                    chr.getClient().getSession().close();
                                }
                            }
                        }
                        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                            cserv.getMapFactory().destroyMap(地图, true);
                            cserv.getMapFactory().HealMap(地图);
                        }
                        删除地图(地图);
                    } catch (InterruptedException e) {
                    }
                }
            }.start();
        } else {
            c.getPlayer().dropMessage(1, "回收失败，此地图在回收队列中。");
        }
    }

    public void 回收地图(final int a) {
        if (判断地图(a) <= 0) {
            final int 地图 = a;
            记录地图(地图);
            c.getPlayer().dropMessage(1, "回收成功，此地图将在 1 小时后被重置。");
            new Thread() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1000 * 60 * 1);
                        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                            cserv.getMapFactory().destroyMap(地图, true);
                            cserv.getMapFactory().HealMap(地图);
                        }
                        删除地图(地图);
                    } catch (InterruptedException e) {
                    }
                }
            }.start();
        } else {
            c.getPlayer().dropMessage(1, "回收失败，此地图在回收队列中。");
        }
    }

    public void 记录地图(int a) {
        try (Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO map (id) VALUES ( ?)")) {
            ps.setInt(1, a);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {

        }
    }

    public void 删除地图(int a) {
        PreparedStatement ps1 = null;
        ResultSet rs = null;
        try {
            ps1 = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM map where id =" + a + "");
            rs = ps1.executeQuery();
            if (rs.next()) {
                String sqlstr = " Delete from map where id = '" + a + "'";
                ps1.executeUpdate(sqlstr);
            }
        } catch (SQLException ex) {

        }
    }

    public int 判断地图(int a) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM map where id =" + a + "");
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                data += 1;
            }
            ps.close();
        } catch (SQLException ex) {
        }
        return data;
    }

    public void 人气排行榜() {
        MapleGuild.人气排行(getClient(), this.npc);
    }

    public void 声望排行榜() {
        MapleGuild.声望排行(getClient(), this.npc);
    }

    public void 豆豆排行榜() {
        MapleGuild.豆豆排行(getClient(), this.npc);
    }

    public void 战斗力排行榜() {
        MapleGuild.战斗力排行(getClient(), this.npc);
    }

    public void 总在线时间排行榜() {
        MapleGuild.总在线时间排行(getClient(), this.npc);
    }

    public int 查询今日在线时间() {
        int data = 0;
        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement psu = con.prepareStatement("SELECT todayOnlineTime FROM characters WHERE id = ?");
            psu.setInt(1, c.getPlayer().getId());
            ResultSet rs = psu.executeQuery();
            if (rs.next()) {
                data = rs.getInt("todayOnlineTime");
            }
            rs.close();
            psu.close();

        } catch (SQLException ex) {
            System.err.println("查询今日在线时间出错：" + ex.getMessage());
        }

        return data;
    }

    public int 查询总在线时间() {
        int data = 0;

        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement psu = con.prepareStatement("SELECT totalOnlineTime FROM characters WHERE id = ?");
            psu.setInt(1, c.getPlayer().getId());
            ResultSet rs = psu.executeQuery();
            if (rs.next()) {
                data = rs.getInt("totalOnlineTime");
            }
            rs.close();
            psu.close();
        } catch (SQLException ex) {
            System.err.println("查询总在线时间出错：" + ex.getMessage());
        }

        return data;
    }

    public int 查询在线人数() {
        int count = 0;
        for (ChannelServer chl : ChannelServer.getAllInstances()) {
            count += chl.getPlayerStorage().getAllCharacters().size();
        }
        return count;
    }
    
     

    //角色ID。背包类型。背包位置cm.判断背包位置是否有物品(角色ID,类型,位置)
    public static int 判断背包位置是否有物品(int a, int b, int c) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryitems WHERE characterid =" + a + " && inventorytype = " + b + " && position = " + c + "");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data += 1;
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("判断背包位置是否有物品 - 数据库查询失败：" + Ex);
        }
        return data;
    }
    //背包类型，背包位置

    public static int 判断背包位置代码(int a, int b, int c) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryitems WHERE characterid =" + a + " && inventorytype = " + b + " && position = " + c + "");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("itemid");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("判断背包位置是否有物品 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    //角色ID，装备代码,穿戴类型
    public static int 判断玩家是否穿戴某装备(int a, int b, int c) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryitems WHERE characterid =" + a + " && itemid = " + b + " && inventorytype = " + c + "");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data += 1;
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("判断玩家是否穿戴某装备 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static int 获取最高玩家等级() {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT MAX(level) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }

        return data;
    }
    
     

    public static int 获取最高等级() {
        int level = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT  `level` FROM characters WHERE gm = 0 ORDER BY `level` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    level = rs.getInt("level");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return level;
    }

    public static int 获取最高玩家人气() {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT MAX(fame) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }

        return data;
    }

    public static String 获取最高人气玩家名字() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `fame` FROM characters WHERE gm = 0 ORDER BY `fame` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("fame");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }

    public static int 获取最高玩家金币() {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT MAX(meso) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }

        return data;
    }

    public static String 获取最高金币玩家名字() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `meso` FROM characters WHERE gm = 0 ORDER BY `meso` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("meso");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }

    public static int 获取最高玩家在线() {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT MAX(totalOnlineTime) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }

        return data;
    }

    public static String 获取最高在线玩家名字() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `totalOnlineTime` FROM characters WHERE gm = 0 ORDER BY `totalOnlineTime` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("totalOnlineTime");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }

    public static String 获取今日在线玩家名字() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `todayOnlineTime` FROM characters WHERE gm = 0 ORDER BY `todayOnlineTime` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("todayOnlineTime");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }

    public static String 获取最强家族名称() {
        String name = "";
        String level = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `GP` FROM guilds  ORDER BY `GP` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("GP");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }

        return String.format("%s", name);
    }

   

    public static String 获取家族族长备注(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT rank1title as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取家族副族长备注(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT rank2title as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取家族一级成员备注(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT rank3title as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取家族二级成员备注(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT rank4title as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取家族三级成员备注(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT rank5title as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取家族族长ID(int guildId) {
        String data = "";
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT leader as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static int 家族成员数(int a) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters ");
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    if (rs.getInt("guildid") == a) {
                        data += 1;
                    }
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族家族成员数失败：" + Ex);
        }
        return data;
    }

    /**
     * ****************************************************************************************************************************************************
     * 排行榜
     *
     * *****************************************************************************************************************************************************
     * @return
     */
    //新排行榜
    public String 等级排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters  WHERE gm = 0 order by level desc");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("level") < gui.Qhms.ConfigValuesMap.get("冒险家等级上限") && rs.getInt("level") > 30) {
                    if (名次 < 10) {
                        String 玩家名字 = rs.getString("name");
                        String 职业 = 职业(rs.getInt("job"));
                        name.append("Top.#e#d").append(名次).append("#n#k   ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  ").append(职业).append("");
                        for (int j = 15 - 职业.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  Lv.#d").append(rs.getInt("level")).append("#k\r\n");
                        名次++;
                    } else if (名次 >= 10 && 名次 <= 99) {
                        String 玩家名字 = rs.getString("name");
                        String 职业 = 职业(rs.getInt("job"));
                        name.append("Top.#e#d").append(名次).append("#n#k  ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  ").append(职业).append("");
                        for (int j = 15 - 职业.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  Lv.#d").append(rs.getInt("level")).append("#k\r\n");
                        名次++;
                    } else if (名次 > 99) {
                        String 玩家名字 = rs.getString("name");
                        String 职业 = 职业(rs.getInt("job"));
                        name.append("Top.#e#d").append(名次).append("#n#k ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  ").append(职业).append("");
                        for (int j = 15 - 职业.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("  Lv.#d").append(rs.getInt("level")).append("#k\r\n");
                        名次++;

                    }
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    public String 满级排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters  WHERE gm = 0 order by level desc");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("level") == gui.Qhms.ConfigValuesMap.get("冒险家等级上限")) {
                    String 玩家名字 = rs.getString("name");
                    String 职业 = 职业(rs.getInt("job"));
                    int 家族编号 = rs.getInt("guildid");
                    name.append("    ");
                    name.append("#b").append(玩家名字).append("#k");
                    for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                        name.append(" ");
                    }
                    name.append("  ").append(职业).append("");
                    for (int j = 15 - 职业.getBytes().length; j > 0; j--) {
                        name.append(" ");
                    }
                    name.append("家族.#d").append(获取家族名称(家族编号)).append("#k\r\n");
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    public String 怪物卡片排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM monsterbook   order by level desc");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("level") == gui.Qhms.ConfigValuesMap.get("冒险家等级上限")) {
                    String 玩家名字 = rs.getString("name");
                    String 职业 = 职业(rs.getInt("job"));
                    int 家族编号 = rs.getInt("guildid");
                    name.append("    ");
                    name.append("#b").append(玩家名字).append("#k");
                    for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                        name.append(" ");
                    }
                    name.append("  ").append(职业).append("");
                    for (int j = 15 - 职业.getBytes().length; j > 0; j--) {
                        name.append(" ");
                    }
                    name.append("家族.#d").append(获取家族名称(家族编号)).append("#k\r\n");
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    //新排行榜
    public String 财富排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE gm = 0 order by meso desc LIMIT 20 ");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("meso") > 0) {
                    if (名次 < 10) {
                        String 玩家名字 = rs.getString("name");
                        String 金币 = rs.getString("meso");
                        name.append("Top.#e#d").append(名次).append("#n#k   ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("     Meso.#d").append(金币).append("#n\r\n");

                        名次++;
                    } else if (名次 >= 10 && 名次 <= 20) {
                        String 玩家名字 = rs.getString("name");
                        String 金币 = rs.getString("meso");
                        name.append("Top.#e#d").append(名次).append("#n#k  ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("     Meso.#d").append(金币).append("#n\r\n");

                        名次++;
                    }
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    //在线排行榜
    public String 在线排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE gm = 0 order by totalOnlineTime desc LIMIT 20 ");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("totalOnlineTime") > 0) {
                    if (名次 < 10) {
                        String 玩家名字 = rs.getString("name");
                        String 总在线 = rs.getString("totalOnlineTime");
                        String 今在线 = rs.getString("todayOnlineTime");
                        name.append("Top.#e#d").append(名次).append("#n#k   ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("     (tal/day).#d[").append(总在线).append(" / ").append(今在线).append("])\r\n");

                        名次++;
                    } else if (名次 >= 10 && 名次 <= 20) {
                        String 玩家名字 = rs.getString("name");
                        String 总在线 = rs.getString("totalOnlineTime");
                        String 今在线 = rs.getString("todayOnlineTime");
                        name.append("Top.#e#d").append(名次).append("#n#k  ");
                        name.append("#b").append(玩家名字).append("#k");
                        for (int j = 13 - 玩家名字.getBytes().length; j > 0; j--) {
                            name.append(" ");
                        }
                        name.append("     (tal/day).#d[").append(总在线).append(" / ").append(今在线).append("])\r\n");
                        名次++;
                    }
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    //在线排行榜
    public String 永恒重生排行榜() {
        int 名次 = 1;
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryequipment order by itemlevel desc LIMIT 20");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("itemlevel") > 0) {
                    if (名次 < 10) {
                        int 玩家ID = 道具id获取主人(rs.getInt("inventoryitemid"));
                        String 玩家名字 = 角色ID取名字(玩家ID);
                        if (角色ID取GM(玩家ID) == 0) {
                            int 道具IP = 道具id获取道具ID(rs.getInt("inventoryitemid"));
                            name.append("Top.#e#d").append(名次).append("#n#k   ");
                            name.append("拥有者:#b").append(玩家名字).append("#k");
                            for (int j = 15 - 玩家名字.getBytes().length; j > 0; j--) {
                                name.append(" ");
                            }
                            name.append(" lv.#r").append(rs.getInt("itemlevel")).append("#k #b#t").append(道具IP).append("##k\r\n");
                            名次++;
                        }
                    } else if (名次 >= 10 && 名次 <= 20) {
                        int 玩家ID = 道具id获取主人(rs.getInt("inventoryitemid"));
                        String 玩家名字 = 角色ID取名字(玩家ID);
                        if (角色ID取GM(玩家ID) == 0) {
                            int 道具IP = 道具id获取道具ID(rs.getInt("inventoryitemid"));
                            name.append("Top.#e#d").append(名次).append("#n#k  ");
                            name.append("拥有者:#b").append(玩家名字).append("#k");
                            for (int j = 15 - 玩家名字.getBytes().length; j > 0; j--) {
                                name.append(" ");
                            }
                            name.append(" lv.#r").append(rs.getInt("itemlevel")).append("#k #b#t").append(道具IP).append("##k\r\n");
                            名次++;
                        }
                    }
                }
            }
        } catch (SQLException ex) {
        }
        name.append("\r\n\r\n");
        return name.toString();
    }

    public static int 道具id获取道具ID(int a) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryitems WHERE inventoryitemid = " + a + "");
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {//itemid
                data = rs.getInt("itemid");
            }
            ps.close();
        } catch (SQLException ex) {
        }
        return data;
    }

    public static int 道具id获取主人(int a) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM inventoryitems WHERE inventoryitemid = " + a + "");
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {//itemid
                data = rs.getInt("characterid");
            }
            ps.close();
        } catch (SQLException ex) {
        }
        return data;
    }
    
     public static int 今日全服总在线时间() {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("todayOnlineTime") > 0) {
                    data += rs.getInt("todayOnlineTime");
                }
            }
        } catch (SQLException ex) {
        }
        return data;
    }

    public static int 今日家族总在线时间(int a) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM characters");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getInt("guildid") == a) {
                    if (rs.getInt("todayOnlineTime") > 0) {
                        data += rs.getInt("todayOnlineTime");
                    }
                }
            }
        } catch (SQLException ex) {
        }
        return data;
    }

    public static int 角色ID取GM(int id) {
        int data = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT gm as DATA FROM characters WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("角色ID取上线喇叭、出错");
        }
        return data;
    }
    
    public void 清除地图物品(int a) {
        getMap(a).removeDrops();
    }

    public String 职业(int a) {
        return getJobNameById(a);
    }
    
     public String 幸运职业() {
        String 职业1 = getJobNameById((MapleParty.幸运职业 - 1));
        String 职业2 = getJobNameById((MapleParty.幸运职业));
        String 职业3 = getJobNameById((MapleParty.幸运职业 + 1));
        String 职业 = 职业1 + "," + 职业2 + "," + 职业3;
        return 职业;
    }
 
     /**
     ******************************************************************************************************************************************************
     * 神秘商人
     * *****************************************************************************************************************************************************
     * @param id
     * @return
     */
    public String 显示商品(int id) {
        StringBuilder name = new StringBuilder();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM mysterious WHERE f = " + id + "");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 编号 = rs.getInt("id");
                int 物品 = rs.getInt("itemid");
                int 数量 = rs.getInt("数量");
                int 点券 = rs.getInt("点卷");
                int 金币 = rs.getInt("金币");
                name.append("   #L").append(编号).append("# #v").append(物品).append("# #b#t").append(物品).append("##k x ").append(数量).append("");
                name.append(" #d[券/币]:#b").append(点券).append("#k/#b").append(金币).append("#k#l\r\n");
            }
        } catch (SQLException ex) {
        }
        return name.toString();
    }

    public void 购买物品(int id) {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM mysterious WHERE f = " + id + "");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 编号 = rs.getInt("id");
                int 物品 = rs.getInt("itemid");
                int 数量 = rs.getInt("数量");
                int 点券 = rs.getInt("点卷");
                int 金币 = rs.getInt("金币");
                gainItem(物品, (short) 数量);
            }

        } catch (SQLException ex) {
        }
    }
    
     public void 清怪() {
        MapleMap map = c.getPlayer().getMap();
        double range = Double.POSITIVE_INFINITY;
        MapleMonster mob;
        for (MapleMapObject monstermo : map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.MONSTER))) {
            mob = (MapleMonster) monstermo;
            map.killMonster(mob, c.getPlayer(), true, false, (byte) 1);
        }
    }
    
}
